• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Drawing.Graphics类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Drawing.Graphics的典型用法代码示例。如果您正苦于以下问题:C# Graphics类的具体用法?C# Graphics怎么用?C# Graphics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Graphics类属于System.Drawing命名空间,在下文中一共展示了Graphics类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Draw

        public override void Draw(System.Drawing.RectangleF dirtyRect)
        {
            var g = new Graphics();

            // NSView does not have a background color so we just use Clear to white here
            g.Clear(Color.White);

            //RectangleF ClientRectangle = this.Bounds;
            RectangleF ClientRectangle = dirtyRect;

            // Calculate the location and size of the drawing area
            // within which we want to draw the graphics:
            Rectangle rect = new Rectangle((int)ClientRectangle.X, (int)ClientRectangle.Y,
                                           (int)ClientRectangle.Width, (int)ClientRectangle.Height);
            drawingRectangle = new Rectangle(rect.Location, rect.Size);
            drawingRectangle.Inflate(-offset, -offset);
            //Draw ClientRectangle and drawingRectangle using Pen:
            g.DrawRectangle(Pens.Red, rect);
            g.DrawRectangle(Pens.Black, drawingRectangle);
            // Draw a line from point (3,2) to Point (6, 7)
            // using the Pen with a width of 3 pixels:
            Pen aPen = new Pen(Color.Green, 3);
            g.DrawLine(aPen, Point2D(new PointF(3, 2)),
                       Point2D(new PointF(6, 7)));

            g.PageUnit = GraphicsUnit.Inch;
            ClientRectangle = new RectangleF(0.5f,0.5f, 1.5f, 1.5f);
            aPen.Width = 1 / g.DpiX;
            g.DrawRectangle(aPen, ClientRectangle);

            aPen.Dispose();

            g.Dispose();
        }
开发者ID:stnk3000,项目名称:sysdrawing-coregraphics,代码行数:34,代码来源:DrawingView.cs


示例2: DrawPaperSheet

        public void DrawPaperSheet(Graphics graphic)
        {
            if (SingleOffset.Paper == null) { return; }
              var comp1 = (int)(SingleOffset.Paper.SizeH / printFormatWidth.Value) * (int)(SingleOffset.Paper.SizeW / printFormatHeight.Value);
              var comp2 = (int)(SingleOffset.Paper.SizeH / printFormatHeight.Value) * (int)(SingleOffset.Paper.SizeW / printFormatWidth.Value);

              if (comp1 > comp2)
              {
            var widthUse = (int)(SingleOffset.Paper.SizeW / printFormatHeight.Value);
            var heightUse = (int)(SingleOffset.Paper.SizeH / printFormatWidth.Value);
            var flipped = widthUse * printFormatHeight.Value > SingleOffset.Paper.SizeW || heightUse * printFormatWidth.Value > SingleOffset.Paper.SizeH;
            Drawing.Draw(graphic, SingleOffset.Paper.SizeW, SingleOffset.Paper.SizeH, (int)printFormatHeight.Value, (int)printFormatWidth.Value, heightUse, widthUse, false, false);
            usePerSheetLabel.Text = comp1 == usePerSheet.Value ? "" : string.Format("Anzahl Nutzen passt nicht.{0}Empfohlen wären {1} Nutzen.", Environment.NewLine, comp1);
            usePerSheetLabel.Update();
              }
              else
              {
            var heightUse = (int)(SingleOffset.Paper.SizeH / printFormatHeight.Value);
            var widthUse = (int)(SingleOffset.Paper.SizeW / printFormatWidth.Value);
            var flipped = widthUse * printFormatWidth.Value > SingleOffset.Paper.SizeW || heightUse * printFormatHeight.Value > SingleOffset.Paper.SizeH;
            Drawing.Draw(graphic, SingleOffset.Paper.SizeW, SingleOffset.Paper.SizeH, (int)printFormatWidth.Value, (int)printFormatHeight.Value, widthUse, heightUse, false, false);
            usePerSheetLabel.Text = comp2 == usePerSheet.Value ? "" : string.Format("Anzahl Nutzen passt nicht.{0}Empfohlen wären {1} Nutzen.", Environment.NewLine, comp2);
            usePerSheetLabel.Update();
              }
        }
开发者ID:Niedda,项目名称:Impressio,代码行数:25,代码来源:SingleOffsetControl.cs


示例3: Paint

                 protected internal override void Paint(Graphics gr)
                 {           
                   var hf = CandleView.BAR_WIDTH / 2;

                   if (m_View.Kind== ViewKind.SideBySide)
                   {
                       var hh = Host.Height / Host.Zoom;

                       gr.FillRectangle(Brushes.Green, this.Left, hh - m_Lay_BuyHeight, hf, m_Lay_BuyHeight);
                       gr.FillRectangle(Brushes.Red, this.Left+hf, hh - m_Lay_SellHeight, hf, m_Lay_SellHeight);
                   }
                   else if (m_View.Kind== ViewKind.Stacked)
                   {
                      var hh = Host.Height / Host.Zoom;

                      gr.FillRectangle(Brushes.Green, this.Left, hh - m_Lay_BuyHeight, CandleView.BAR_WIDTH, m_Lay_BuyHeight);
                      gr.FillRectangle(Brushes.Red, this.Left, hh - m_Lay_BuyHeight-m_Lay_SellHeight, CandleView.BAR_WIDTH, m_Lay_SellHeight);
                   }
                   else//centered
                   {
                      var mid = (Host.Height / 2) / Host.Zoom;

                      gr.FillRectangle(Brushes.Green, this.Left, mid - m_Lay_BuyHeight, CandleView.BAR_WIDTH, m_Lay_BuyHeight);
                      gr.FillRectangle(Brushes.Red, this.Left, mid, CandleView.BAR_WIDTH, m_Lay_SellHeight);
                   }
                 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:26,代码来源:CandleBuySellView.cs


示例4: PaintJunk

        public void PaintJunk(Graphics g)
        {
            g.FillRectangle(Brushes.Transparent, 0, 0, 1000, 1000);

            using (Font font = new Font("Courier New", 20, FontStyle.Bold))
            {
                if (bounceCounter == -1) return;
                const string str = "DEVELOPER BUILD";
                float x = 0;
                int timefactor = bounceCounter;
                for (int i = 0; i < str.Length; i++)
                {
                    string slice = str.Substring(i, 1);
                    g.PageUnit = GraphicsUnit.Pixel;
                    x += g.MeasureString(slice, font).Width - 1;

                    int offset = -i * 3 + timefactor*3;
                    int yofs = 0;
                    if (offset < 0)
                    { continue; }
                    else
                        if (offset < DigitTable.Length)
                            yofs = DigitTable[offset];
                    g.DrawString(slice, font, Brushes.Black, 5 + x, 15 - yofs);
                }
            }
        }
开发者ID:cas1993per,项目名称:bizhawk,代码行数:27,代码来源:AboutBox.cs


示例5: DoPaint

 public override void DoPaint(Graphics g)
 {
     using (Brush b = new SolidBrush(ZenParams.WindowColor))
     {
         g.FillRectangle(b, 0, 0, Width, Height);
     }
 }
开发者ID:sheeeng,项目名称:Zydeo,代码行数:7,代码来源:SettingsControl.cs


示例6: DrawSelf

 public override void DrawSelf(Graphics grfx)
 {
     grfx.Transform = this.TransformMatrix.GetMatrix();
     grfx.FillRectangle(new SolidBrush(Color.FromArgb(Transparency, FillColor)), Rectangle);
     grfx.DrawRectangle(new Pen(LineColor, LineWidth), Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height);
     grfx.Transform.Reset();
 }
开发者ID:iprodanov,项目名称:IPDrawing,代码行数:7,代码来源:RectangleShape.cs


示例7: DrawAppointment

        public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners)
        {
            if (appointment == null)
                throw new ArgumentNullException("appointment");

            if (g == null)
                throw new ArgumentNullException("g");

            if (rect.Width != 0 && rect.Height != 0)
                using (StringFormat format = new StringFormat())
                {
                    format.Alignment = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Near;

                    if ((appointment.Locked) && isSelected)
                    {
                        // Draw back
                        using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color))
                            g.FillRectangle(m_Brush, rect);
                    }
                    else
                    {
                        // Draw back
                        using (SolidBrush m_Brush = new SolidBrush(appointment.Color))
                            g.FillRectangle(m_Brush, rect);
                    }

                    if (isSelected)
                    {
                        using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                            g.DrawRectangle(m_Pen, rect);

                        Rectangle m_BorderRectangle = rect;

                        m_BorderRectangle.Inflate(2, 2);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);

                        m_BorderRectangle.Inflate(-4, -4);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);
                    }
                    else
                    {
                        // Draw gripper
                        gripRect.Width += 1;

                        using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor))
                            g.FillRectangle(m_Brush, gripRect);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, rect);
                    }

                    rect.X += gripRect.Width;
                    g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format);
                }
        }
开发者ID:bshultz,项目名称:ctasks,代码行数:60,代码来源:Office11Renderer.cs


示例8: Measure

        public override SizeF Measure(Graphics graphics)
		{
			if (this.Image != null)
			{
				SizeF size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);

				if (this.Width.HasValue)
					size.Width = Math.Max(size.Width, this.Width.Value);
				else
					size.Width = Math.Max(size.Width, this.Image.Width);

				if (this.Height.HasValue)
					size.Height = Math.Max(size.Height, this.Height.Value);
				else
					size.Height = Math.Max(size.Height, this.Image.Height);
				
				return size;
			} else
			{
				var size = new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
				if (this.Width.HasValue)
					size.Width = Math.Max(size.Width, this.Width.Value);

				if (this.Height.HasValue)
					size.Height = Math.Max(size.Height, this.Height.Value);
				
				return size;
			}
		}
开发者ID:coreafive,项目名称:XLE,代码行数:29,代码来源:NodeImageItem.cs


示例9: GetCharacterSize

        public virtual Size GetCharacterSize( Graphics g, Font font, CharacterCasing casing )
        {
            const int MeasureCharCount = 10;

             Size charSize = new Size( 0, 0 );

             for ( char c = '0'; c <= '9'; ++c )
             {
            Size newSize = TextRenderer.MeasureText( g, new string( c, MeasureCharCount ), font, new Size( 0, 0 ),
               _textFormatFlags );

            newSize.Width = (int)Math.Ceiling( (double)newSize.Width / (double)MeasureCharCount );

            if ( newSize.Width > charSize.Width )
            {
               charSize.Width = newSize.Width;
            }

            if ( newSize.Height > charSize.Height )
            {
               charSize.Height = newSize.Height;
            }
             }

             return charSize;
        }
开发者ID:EddyBeaupre,项目名称:WinCDP-GUI,代码行数:26,代码来源:DecimalValue.cs


示例10: DrawBrick

		static protected void DrawBrick (Graphics graphics, Brush b1, Brush b2, Brush b3)
		{
			if (graphics == null) return;
			graphics.FillPolygon (b1, brickPoints1);
			graphics.FillPolygon (b2, brickPoints2);
			graphics.FillPolygon (b3, brickPoints3);
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:7,代码来源:MethodShape.cs


示例11: CalcReciprocals

		private static SizeF CalcReciprocals(Graphics g)	
		{
			switch(g.PageUnit)	
			{	
				case GraphicsUnit.World:	
				case GraphicsUnit.Pixel:
					
					return new SizeF(1f,1f);
					
				case GraphicsUnit.Inch:
					
					return new SizeF(1f/g.DpiX,1f/g.DpiY);
					
				case GraphicsUnit.Millimeter:
					
					return new SizeF(25.4f/g.DpiX,25.4f/g.DpiY);
					
				case GraphicsUnit.Point:
					
					return new SizeF(72f/g.DpiX,72f/g.DpiY);
					
				case GraphicsUnit.Display:
					
					return new SizeF(75f/g.DpiX,75f/g.DpiY);
					
				case GraphicsUnit.Document:
					
					return new SizeF(300f/g.DpiX,300f/g.DpiY);
					
			}
			return new SizeF(10,10);//never gets here...
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:32,代码来源:Ruler.cs


示例12: VisibleSurface

 public VisibleSurface(Graphics graphics, int wdth, int hght)
     : base(wdth, hght)
 {
     base.DC = graphics;
     base.Buffer = new Backbuffer(this);
     this.RedrawDirtyRectangleOnly = true;
 }
开发者ID:Isthimius,项目名称:Gondwana,代码行数:7,代码来源:VisibleSurface.cs


示例13: Paint

 /// <summary>
 /// Paints the wrapped IOGraph onto the specified viewport. Does nothing if no 
 /// IOGraph has been provided.
 /// </summary>
 public void Paint(Graphics g, Rectangle viewportArea, float zoomFactor)
 {
     if(null != _graph) {
         _layoutManager.Layout(_graph, viewportArea.Size);
         _graphPainter.PaintNetwork(_graph, g, viewportArea, zoomFactor);
     }
 }
开发者ID:BLueders,项目名称:SharpNeat_Playground,代码行数:11,代码来源:IOGraphViewportPainter.cs


示例14: PaintVoxel

        void PaintVoxel(Graphics graphics, int i, int j)
        {
            Brush brushVoxel_True = new SolidBrush(Color.FromArgb(181, 230, 29));
            Brush brushVoxel_False = new SolidBrush(Color.FromArgb(240, 240, 240));

            graphics.FillRectangle(VoxelsData[i, j] ? brushVoxel_True : brushVoxel_False, VoxelSize * i + 1, VoxelSize * j + 1, VoxelSize - 1, VoxelSize - 1);
        }
开发者ID:xdray,项目名称:CubeWorld,代码行数:7,代码来源:MainForm.cs


示例15: Draw

		internal override void Draw(Graphics g)
		{
			IsInvalidated = false;

			Rectangle r = BaseElement.GetUnsignedRectangle(new Rectangle(location, size));

			Point[] points = new Point[5];
			points[0] = new Point(r.X + 0, r.Y + 0);
			points[1] = new Point(r.X + 0, r.Y + r.Height);
			points[2] = new Point(r.X + r.Width, r.Y + r.Height);

			//Fold
			points[3] = new Point(r.X + r.Width, r.Y + foldSize.Height);
			points[4] = new Point(r.X + r.Width - foldSize.Width, r.Y + 0);

			//foreach(Point p in points) p.Offset(location.X, location.Y);

			g.FillPolygon(GetBrush(r), points, FillMode.Alternate);
			g.DrawPolygon(new Pen(borderColor, borderWidth), points);

			g.DrawLine(new Pen(borderColor, borderWidth),
			           new Point(r.X + r.Width - foldSize.Width, r.Y + foldSize.Height),
			           new Point(r.X + r.Width, r.Y + foldSize.Height));

			g.DrawLine(new Pen(borderColor, borderWidth),
			           new Point(r.X + r.Width - foldSize.Width, r.Y + 0),
			           new Point(r.X + r.Width - foldSize.Width, r.Y + 0 + foldSize.Height));
		}
开发者ID:froggy96,项目名称:diagramnet,代码行数:28,代码来源:CommentBoxElement.cs


示例16: Board

 /// <summary>
 /// Constructor called that clears the field and also draws the board. 
 /// </summary>
 /// <param name="g">The Graphics of the panel it draws on.</param>
 /// <param name="difficulty">The Difficulty of the Bot!</param>
 public Board(Graphics g, BotDifficulty difficulty)
 {
     _graphics = g;
     _botDifficulty = difficulty;
     ClearField();
     DrawField();
 }
开发者ID:Smallxmac,项目名称:TicTacToeGame,代码行数:12,代码来源:Board.cs


示例17: PaintThisProgress

		/// <summary></summary>
		/// <param name="box"></param>
		/// <param name="g"></param>
		protected override void PaintThisProgress(Rectangle box, Graphics g) {
			try {
				box.Width -= 1;
				box.Height -= 1;
			} catch {}
			if (box.Width <= 1) {
				return;
			}

			g.FillRectangle(brush, box);
			Rectangle innerBox = box;
			innerBox.Inflate(-1, -1);
			g.DrawRectangle(inner, innerBox);
			g.DrawLine(outer, box.X, box.Y, box.Right, box.Y);
			g.DrawLine(outer, box.X, box.Y, box.X, box.Bottom);
			g.DrawLine(edge, box.X, box.Bottom, box.Right, box.Bottom);

			if (gloss != null) {
				gloss.PaintGloss(box, g);
			}

			if (showEdge) {
				g.DrawLine(edge, box.Right, box.Y, box.Right, box.Bottom);
			}
		}
开发者ID:hoeness2,项目名称:mcebuddy2,代码行数:28,代码来源:RarProgressPainter.cs


示例18: Paint

 public override void Paint(Graphics g)
 {
     if (g == null)
         throw new ArgumentNullException("The Graphics object is 'null'");
     From.Paint(g);
     To.Paint(g);
 }
开发者ID:Tom-Hoinacki,项目名称:OO-CASE-Tool,代码行数:7,代码来源:ConnectionBase.cs


示例19: Render

        // Methods
        public void Render(Graphics g, Character c)
        {
            int x, y;

            x = c.Location.X * m_blockSize;
            y = m_headerSize + c.Location.Y * m_blockSize;

            if (m_frame == 0)
            {
                RenderClosed(g, x, y);
            }
            else
            {
                if (c.Direction == Direction.Up)
                {
                    RenderUp(g, x, y);
                }
                else if (c.Direction == Direction.Right)
                {
                    RenderRight(g, x, y);
                }
                else if (c.Direction == Direction.Down)
                {
                    RenderDown(g, x, y);
                }
                else
                {
                    RenderLeft(g, x, y);
                }
            }

            m_frame = (m_frame + 1) % MaxFrames;
        }
开发者ID:JohnHiness,项目名称:pacman-csharp,代码行数:34,代码来源:CharacterRenderer.cs


示例20: Paint

 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     var buttonRectangle = new Rectangle(cellBounds.X + 2, cellBounds.Y + 2, cellBounds.Width - 4, cellBounds.Height - 4);
     base.Paint(graphics, clipBounds, buttonRectangle, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     var imageRectangle = new Rectangle(cellBounds.X + 6, cellBounds.Y + 6, _detailImage.Width, _detailImage.Height);
     graphics.DrawImage(_detailImage, imageRectangle);
 }
开发者ID:pragmasolutions,项目名称:Libreria,代码行数:7,代码来源:DetailsColumn.cs



注:本文中的System.Drawing.Graphics类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Drawing.Icon类代码示例发布时间:2022-05-26
下一篇:
C# Drawing.FontFamily类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap