在其他对象位置旁边创建一个新的Rectangle

时间:2013-03-16 17:03:23

标签: c# .net winforms

所以,我想立即在图片框旁边创建一个新的矩形。想象一下,我写的矩形位置等于PictureBox1位置加上x + 10。如何在C#中做到这一点?!

2 个答案:

答案 0 :(得分:1)

您可以使用指定x,y,width和height的构造函数Rectangle(int,int,int,int)来创建新的Rectangle。 因此,使用先前的Rectangle的x + 10,y,width,height作为参数。

Rectangle newRect = new Rectangle(
  pictureBox1.Location.X + 10, 
  pictureBox1.Location.Y, 
  pictureBox1.Width, 
  pictureBox1.Heigth);

答案 1 :(得分:0)

像这样的东西。是从头顶做的,所以你可能会有一些错误名称的属性。

 Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0), 1);
 e.Graphics.DrawRectangle(
    blackPen, 
    pictureBox1.Location.X + 10, 
    pictureBox1.Location.Y, 
    pictureBox1.Size.Width, 
    pictureBox1.Size.Heigth);

(JustGoogleIt)