在C#中有一个pannel控件,我现在想在上面画矩形,当画完一个矩形,要记住矩形的位置以及大小,松开鼠标后矩形消失!怎么弄?请教高手!
在C#中有一个pannel控件,我现在想在上面画矩形,当画完一个矩形,要记住矩形的位置以及大小,松开鼠标后矩形消失!怎么弄?请教高手!--------------------编程问答-------------------- 帮你顶一下 --------------------编程问答-------------------- xml记录一下? --------------------编程问答-------------------- 谢了,有没有例子我看一下,对这个一无所知,学winform不久,请高手指点一下! --------------------编程问答-------------------- pannel控件上有鼠标的按下事件panel1_MouseDown和panel1_MouseUp利用这两个事件。来计算。在鼠标按下的时候,记住那个点( intX = e.X;
intY = e.Y;)在鼠标弹起的时候,记住这个点。利用这两个点计算。画好以后。不刷新的话。是不显示的。 --------------------编程问答-------------------- You might use ControlPaint.DrawReversibleFrame:
public partial class Form1 : Form
{
Point startPoint;
Rectangle lastRect;
bool isDragging;
public Form1()
{
InitializeComponent();
}
protected override void OnMouseDown(MouseEventArgs e)
{
startPoint = this.PointToScreen(e.Location);
lastRect = new Rectangle(0, 0, 0, 0);
isDragging = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (isDragging )
{
Point current = this.PointToScreen(e.Location);
int width = current.X - startPoint.X;
int height = current.Y - startPoint.Y;
ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);
lastRect = new Rectangle(startPoint, new Size(width, height));
ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (isDragging)
{
isDragging = false;
ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);
MessageBox.Show("the rect is " + lastRect);
}
}
}
From: GDI +画橡皮线的问题 --------------------编程问答-------------------- blog.csdn.net/dunao
看看这个吧!应该就是你想要的
--------------------编程问答-------------------- 要在OnMouseDown和OnMouseMove事件里面用e.X,和e.Y坐标来取得长和宽
然后记录下来作为你矩形的长和宽
补充:.NET技术 , C#