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

C# Drawing.Rectangle类代码示例

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

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



Rectangle类属于System.Drawing命名空间,在下文中一共展示了Rectangle类的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: RECT

		public RECT(Rectangle rect) 
		{
			Left = rect.Left; 
			Top = rect.Top;
			Right = rect.Right;
			Bottom = rect.Bottom;
		}
开发者ID:RodrigoDotNet,项目名称:gerador-de-camadas,代码行数:7,代码来源:HelperFunctions.cs


示例3: OnSizeChanged

        protected override void OnSizeChanged(EventArgs e)
        {
			base.OnSizeChanged(e);

            boxOffset = Height / 2 - 9;
            boxRectangle = new Rectangle(boxOffset, boxOffset, CHECKBOX_SIZE - 1, CHECKBOX_SIZE - 1);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:Google-Play-Music-Desktop-Player-UNOFFICIAL-,代码行数:7,代码来源:MaterialCheckbox.cs


示例4: ButtonDragRectangleEventArgs

 /// <summary>
 /// Initialize a new instance of the ButtonDragRectangleEventArgs class.
 /// </summary>
 /// <param name="point">Left mouse down point.</param>
 public ButtonDragRectangleEventArgs(Point point)
 {
     _point = point;
     _dragRect = new Rectangle(_point, Size.Empty);
     _dragRect.Inflate(SystemInformation.DragSize);
     _preDragOffset = true;
 }
开发者ID:Cocotteseb,项目名称:Krypton,代码行数:11,代码来源:ButtonDragRectangleEventArgs.cs


示例5: 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


示例6: CalcDifference

        public static void CalcDifference(Bitmap bmp1, Bitmap bmp2)
        {
            PixelFormat pxf = PixelFormat.Format32bppArgb;
            Rectangle rect = new Rectangle(0, 0, bmp1.Width, bmp1.Height);

            BitmapData bmpData1 = bmp1.LockBits(rect, ImageLockMode.ReadWrite, pxf);
            IntPtr ptr1 = bmpData1.Scan0;

            BitmapData bmpData2 = bmp2.LockBits(rect, ImageLockMode.ReadOnly, pxf);
            IntPtr ptr2 = bmpData2.Scan0;

            int numBytes = bmp1.Width * bmp1.Height * bytesPerPixel;
            byte[] pixels1 = new byte[numBytes];
            byte[] pixels2 = new byte[numBytes];

            System.Runtime.InteropServices.Marshal.Copy(ptr1, pixels1, 0, numBytes);
            System.Runtime.InteropServices.Marshal.Copy(ptr2, pixels2, 0, numBytes);

            for (int i = 0; i < numBytes; i += bytesPerPixel)
            {
                if (pixels1[i + 0] == pixels2[i + 0] &&
                    pixels1[i + 1] == pixels2[i + 1] &&
                    pixels1[i + 2] == pixels2[i + 2])
                {
                    pixels1[i + 0] = 255;
                    pixels1[i + 1] = 255;
                    pixels1[i + 2] = 255;
                    pixels1[i + 3] = 0;
                }
            }

            System.Runtime.InteropServices.Marshal.Copy(pixels1, 0, ptr1, numBytes);
            bmp1.UnlockBits(bmpData1);
            bmp2.UnlockBits(bmpData2);
        }
开发者ID:vebin,项目名称:PhotoBrushProject,代码行数:35,代码来源:TransfromHelper.cs


示例7: CorrectPosition

    /// <summary>
    /// Returns the position closest to the given position such that this
    /// form will be completely on the screen.  E.g., if the form would be
    /// cropped off the right side of the screen, the returned point would
    /// have the same Y position and a lesser X position such that the right
    /// side of the form would be flush with the right side of the screen if
    /// it were placed at the given position.
    /// </summary>
    private Point CorrectPosition(Point position) {
      Point newPosition = new Point(position.X, position.Y);

      // Figure out the bounds of all screens (we just round if the monitors
      // happen to be different sizes).
      Rectangle screenBounds = Screen.FromControl(this).WorkingArea;
      int left = screenBounds.Left;
      int top = screenBounds.Top;
      int right = screenBounds.Right;
      int bottom = screenBounds.Bottom;
      foreach (Screen screen in Screen.AllScreens) {
        left = Math.Min(screen.WorkingArea.Left, left);
        top = Math.Min(screen.WorkingArea.Top, top);
        right = Math.Max(screen.WorkingArea.Right, right);
        bottom = Math.Max(screen.WorkingArea.Bottom, bottom);
      }
      Rectangle workingBounds = new Rectangle(left, top, right - left, bottom - top);

      Rectangle formBounds = this.Bounds;
      if (newPosition.X < workingBounds.Left) {
        newPosition.X = workingBounds.Left;
      } else if (newPosition.X + formBounds.Width > workingBounds.Right) {
        newPosition.X = workingBounds.Right - formBounds.Width;
      }
      if (newPosition.Y < workingBounds.Top) {
        newPosition.Y = workingBounds.Top;
      } else if (newPosition.Y + formBounds.Height > workingBounds.Bottom) {
        newPosition.Y = workingBounds.Bottom - formBounds.Height;
      }
      return newPosition;
    }
开发者ID:tetuji,项目名称:stickies-windows,代码行数:39,代码来源:ContainedForm.cs


示例8: PortLinkGlyph

 public PortLinkGlyph(string id, Rectangle bounds)
     : base(id)
 {
     _From = bounds.Location;
     _To = new Point (bounds.X + bounds.Width, bounds.Y + bounds.Height);
     BuildContactPoints ();
 }
开发者ID:poobalan-arumugam,项目名称:stateproto,代码行数:7,代码来源:PortLinkGlyph.cs


示例9: 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


示例10: Apply

        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
开发者ID:Grifs99,项目名称:ShareX,代码行数:29,代码来源:GrayscaleFilter.cs


示例11: 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


示例12: DrawGraphics

        void DrawGraphics(Object sender, PaintEventArgs PaintNow)
        {
            Rectangle Dot = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight); // Create rectangle (start position, and size X & Y)
            SolidBrush WhiteBrush = new SolidBrush(Color.White); // Create Brush(Color) to paint rectangle

            PaintNow.Graphics.FillRectangle(WhiteBrush, Dot);
        }
开发者ID:JeremiahZhang,项目名称:AKA,代码行数:7,代码来源:Program.cs


示例13: GetNextPoint

        public unsafe Point GetNextPoint(Rectangle rectTrack, byte* pIn, Size sizeIn, double[] Qu, double[] PuY0)
        {
            double[] w = new double[256];//方向权值
            for (int i = 0; i < 256; i++)
            {
                w[i] = Math.Sqrt(Qu[i] / PuY0[i]);
            }

            PointF center = new PointF(
                (float)rectTrack.Left + (float)rectTrack.Width / 2,
                (float)rectTrack.Top + (float)rectTrack.Height / 2);
            SizeF H = new SizeF((float)rectTrack.Width / 2, (float)rectTrack.Height / 2);
            double numeratorX = 0, numeratorY = 0;//分子
            double denominatorX = 0, denominatorY = 0;//分母
            for (int y = rectTrack.Top; y < rectTrack.Bottom; y++)
            {
                for (int x = rectTrack.Left; x < rectTrack.Right; x++)
                {
                    int index = DataManager.GetIndex(x, y, sizeIn.Width);
                    byte u = pIn[index];
                    //计算以高斯分布为核函数自变量X的值
                    double X = ((Math.Pow((x - center.X), 2) + Math.Pow((y - center.Y), 2))
                            / (Math.Pow(H.Width, 2) + Math.Pow(H.Height, 2)));
                    //负的高斯分布核函数的值
                    double Gi = -Math.Exp(-Math.Pow(X, 2) / 2) / Math.Sqrt(2 * Math.PI);

                    numeratorX += x * w[u] * Gi;
                    numeratorY += y * w[u] * Gi;
                    denominatorX += w[u] * Gi;
                    denominatorY += w[u] * Gi;
                }
            }
            return new Point((int)(numeratorX / denominatorX), (int)(numeratorY / denominatorY));
        }
开发者ID:dalinhuang,项目名称:my-computer-vision,代码行数:34,代码来源:MeanShift.cs


示例14: Apply

 public void Apply(Surface dst, Surface src, Rectangle[] rois, int startIndex, int length)
 {
     for (int i = startIndex; i < startIndex + length; ++i)
     {
         ApplyBase(dst, rois[i].Location, src, rois[i].Location, rois[i].Size);
     }
 }
开发者ID:nkaligin,项目名称:paint-mono,代码行数:7,代码来源:PixelOp.cs


示例15: SetLocation

		protected virtual void SetLocation()
		{
			TextArea textArea = control.ActiveTextAreaControl.TextArea;
			TextLocation caretPos  = textArea.Caret.Position;
			
			int xpos = textArea.TextView.GetDrawingXPos(caretPos.Y, caretPos.X);
			int rulerHeight = textArea.TextEditorProperties.ShowHorizontalRuler ? textArea.TextView.FontHeight : 0;
			Point pos = new Point(textArea.TextView.DrawingPosition.X + xpos,
			                      textArea.TextView.DrawingPosition.Y + (textArea.Document.GetVisibleLine(caretPos.Y)) * textArea.TextView.FontHeight
			                      - textArea.TextView.TextArea.VirtualTop.Y + textArea.TextView.FontHeight + rulerHeight);
			
			Point location = control.ActiveTextAreaControl.PointToScreen(pos);
			
			// set bounds
			Rectangle bounds = new Rectangle(location, drawingSize);
			
			if (!workingScreen.Contains(bounds)) {
				if (bounds.Right > workingScreen.Right) {
					bounds.X = workingScreen.Right - bounds.Width;
				}
				if (bounds.Left < workingScreen.Left) {
					bounds.X = workingScreen.Left;
				}
				if (bounds.Top < workingScreen.Top) {
					bounds.Y = workingScreen.Top;
				}
				if (bounds.Bottom > workingScreen.Bottom) {
					bounds.Y = bounds.Y - bounds.Height - control.ActiveTextAreaControl.TextArea.TextView.FontHeight;
					if (bounds.Bottom > workingScreen.Bottom) {
						bounds.Y = workingScreen.Bottom - bounds.Height;
					}
				}
			}
			Bounds = bounds;
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:35,代码来源:AbstractCompletionWindow.cs


示例16: DrawBitmap

 public Bitmap DrawBitmap(int theight, int twidth)
 {
     Bitmap bitmap3;
     Bitmap bitmap = new Bitmap(this.Width, this.Height);
     Rectangle targetBounds = new Rectangle(0, 0, this.Width, this.Height);
     this.MyBrowser.DrawToBitmap(bitmap, targetBounds);
     Image image = bitmap;
     Bitmap bitmap2 = new Bitmap(twidth, theight, image.PixelFormat);
     Graphics graphics = Graphics.FromImage(bitmap2);
     graphics.CompositingQuality = CompositingQuality.HighSpeed;
     graphics.SmoothingMode = SmoothingMode.HighSpeed;
     graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
     Rectangle rect = new Rectangle(0, 0, twidth, theight);
     graphics.DrawImage(image, rect);
     try
     {
         bitmap3 = bitmap2;
     }
     catch
     {
         bitmap3 = null;
     }
     finally
     {
         image.Dispose();
         image = null;
         this.MyBrowser.Dispose();
         this.MyBrowser = null;
     }
     return bitmap3;
 }
开发者ID:xiluo,项目名称:document-management,代码行数:31,代码来源:WebPageBitmap.cs


示例17: RtlTransform

 public static Rectangle RtlTransform(Control control, Rectangle rectangle)
 {
     if (control.RightToLeft != RightToLeft.Yes)
         return rectangle;
     else
         return new Rectangle(control.ClientRectangle.Right - rectangle.Right, rectangle.Y, rectangle.Width, rectangle.Height);
 }
开发者ID:hanistory,项目名称:hasuite,代码行数:7,代码来源:DrawHelper.cs


示例18: OnMouseDown

		protected override void OnMouseDown(MouseEventArgs e)
		{
			// get the index of the clicked item
			_rowIndexFromMouseDown = HitTest(e.X, e.Y).RowIndex;

			// basic mouse handling has right clicks show context menu without changing selection, so we handle it manually here
			if (e.Button == MouseButtons.Right)
				HandleRightMouseDown(e);

			// call the base class, so that the row gets selected, etc.
			base.OnMouseDown(e);

			if (_rowIndexFromMouseDown > -1)
			{
				// Remember the point where the mouse down occurred. 
				// The DragSize indicates the size that the mouse can move 
				// before a drag event should be started.                
				Size dragSize = SystemInformation.DragSize;

				// Create a rectangle using the DragSize, with the mouse position being
				// at the center of the rectangle.
				_dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width/2), e.Y - (dragSize.Height/2)), dragSize);
			}
			else
			{
				// Reset the rectangle if the mouse is not over an item in the ListBox.
				_dragBoxFromMouseDown = Rectangle.Empty;
			}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:29,代码来源:DataGridViewWithDragSupport.cs


示例19: CalculateActorSelectionPriority

        static long CalculateActorSelectionPriority(ActorInfo info, Rectangle bounds, int2 selectionPixel)
        {
            var centerPixel = new int2(bounds.X, bounds.Y);
            var pixelDistance = (centerPixel - selectionPixel).Length;

            return ((long)-pixelDistance << 32) + info.SelectionPriority();
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:7,代码来源:SelectableExts.cs


示例20: DrawDropImage

        private Bitmap DrawDropImage(int size)
        {
            Bitmap bmp = new Bitmap(size, size);
            Rectangle rect = new Rectangle(0, 0, size, size);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.FillRectangle(Brushes.CornflowerBlue, rect);

                g.DrawRectangleProper(Pens.Black, rect);

                using (Pen pen = new Pen(Color.WhiteSmoke, 5) { Alignment = PenAlignment.Inset })
                {
                    g.DrawRectangleProper(pen, rect.Offset(-1));
                }

                string text = Resources.DropForm_DrawDropImage_Drop_here;

                using (Font font = new Font("Arial", 20, FontStyle.Bold))
                using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
                {
                    g.DrawString(text, font, Brushes.Black, rect.LocationOffset(1), sf);
                    g.DrawString(text, font, Brushes.White, rect, sf);
                }
            }

            return bmp;
        }
开发者ID:Grifs99,项目名称:ShareX,代码行数:28,代码来源:DropForm.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Drawing.RectangleF类代码示例发布时间:2022-05-26
下一篇:
C# Drawing.Rect类代码示例发布时间: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