如何在PictureBox中选择和移动形状(线,曲线)? [英] How to select and move shapes(Line,Curve) in PictureBox?

查看:68
本文介绍了如何在PictureBox中选择和移动形状(线,曲线)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

List<Point> points = new List<Point>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
            if (e.Button == MouseButtons.Left)
            {
                points.Add(e.Location);
                pictureBox1.Invalidate();
               
            }
}


private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
             if (points.Count > 1)
                e.Graphics.DrawLines(Pens.Magenta, points.ToArray());
}


我一直在画线,曲线......我有个按钮:btnDrawLine,btnDrawCurve
每按一次按钮将调用一个绘制函数.按此按钮时,会将一个项目添加到列表框中.
例如:单击btnDrawLine-> "combobox"添加行.
用户可以通过在列表框中选择名称来移动直线或曲线.
我该怎么办?
谢谢.我将一个对象(直线,曲线)放入PictureBox.


I have been drawing lines, curves, ...I have the button: btnDrawLine, btnDrawCurve
Each button press will call a function to draw.When you press the button, an item be added to the listbox.
For example:click btnDrawLine-> "combobox" add Line.
The user can move the line or curve by selecting the name in the listbox.
How do I do this?
thank.I will put an object (line, Curve) into a PictureBox.
How to a PictureBox always display when other PictureBox override it?

推荐答案

这很简单:不要使用PictureBox.与从System.Windows.Forms.Control派生的自定义控件相比,将此控件用于功能会带来更多麻烦而不是帮助,这是一个常见错误.
您可以在我过去的答案中找到更详细的解释:
如何从旧图纸中清除面板 [ ^ ],
Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [在mdi子表单之间画线 [在面板上捕获图形 [
This is simple: don''t use PictureBox. This is a common mistake to use this control for the functionality where it presents much more hassles then help compared to the custom control derived from System.Windows.Forms.Control.

You can find more detailed explanations in my past answers:
How do I clear a panel from old drawing[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^].

After reading some of my answers references above you will know exactly what to do.

—SA


这篇关于如何在PictureBox中选择和移动形状(线,曲线)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆