如何在c#中使用鼠标事件重新调整我的矩形?

时间:2018-04-06 13:01:21

标签: c# gdi+

我已经在图片框图像上绘制了多个矩形。我想使用鼠标事件调整所有矩形的大小。任何人都可以帮我解决这个问题吗?

public List<rectangle> listRec = new List<rectangle>();
Graphics g;
//private Graphics g; 
Point startPos; 
Point currentPos;
bool drawing; 
Rectangle r1;
Rectangle rect = new Rectangle();

private Rectangle getRectangle()
{
    r1 = new Rectangle(
    Math.Min(startPos.X, currentPos.X),
    Math.Min(startPos.Y, currentPos.Y),
    Math.Abs(startPos.X - currentPos.X),
    Math.Abs(startPos.Y - currentPos.Y));
    return r1;
}

private void button1_Click(object sender, EventArgs e)
{

String data;

Font font = new Font("Arial", 14);
arg1 = Convert.ToInt32(textBox1.Text);
arg2 = Convert.ToInt32(textBox2.Text);
Rectangle rect = new Rectangle();
rect.Size = new Size(40, 65);
for (int x = 0; x < arg1; x++)
{
    // rect.X = x * rect.Width;
    rect.X = x * (rect.Width + 30) + 73;
    for (int y = 0; y < arg2; y++)
    {
        rect.Y = y * (rect.Height + 35) + 38;
        listRec.Add(rect);
        data = rect.ToString();
        TextWriter txt = new StreamWriter("E:\\B1Pockets.txt", true);
        txt.WriteLine(data);
        txt.Close();
        // MessageBox.Show(rect.ToString());
    }
}

foreach (Rectangle rec in listRec)
{
    g = pictureBox1.CreateGraphics();
    Pen p = new Pen(Color.Red, 3);
    g.DrawRectangle(p, rec);
    g.DrawString("p1", font, new SolidBrush(Color.Yellow), (rect.Width + 30), 35);
    g.DrawString("p2", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 60, 35);
    g.DrawString("p3", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 130, 35);
    g.DrawString("p4", font, new SolidBrush(Color.Yellow), (rect.Width + 30), (rect.Height + 30) + 40);
    g.DrawString("p5", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 60, (rect.Height + 30) + 40);
    g.DrawString("p6", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 130, (rect.Height + 30) + 40);
}

}

我已经尝试了这个代码到我的应用程序。我以2 * 3的方式绘制矩形。并在其上方绘制一个大矩形。简而言之,我的图片框包含许多矩形,我想为所有矩形添加调整大小选项C#

0 个答案:

没有答案