感谢版主回复
我想用Graphic DrawRectangle 在imageViewer1 上画矩形,但是不知道为什么不成功,但是以picturebox1上可以的,leadtools自带的draw没整明白,请版主大人,帮忙看下,或者写个简单的例子,万分感谢。
private Point m_ptStart = new Point(0, 0);
private Point m_ptEnd = new Point(0, 0);
// true: MouseUp or false: MouseMove
private bool m_bMouseDown = false;
void ImageViewer1MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
if (!m_bMouseDown)
{
m_ptStart = new Point(e.X, e.Y);
m_ptEnd = new Point(e.X, e.Y);
}
m_bMouseDown = !m_bMouseDown;
}
void ImageViewer1MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
m_ptEnd = new Point(e.X, e.Y);
this.imageViewer1.Refresh();
}
void ImageViewer1MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
if (m_ptStart.X >= 0 && m_ptEnd.X >= 0
&& m_ptStart.Y >= 0 && m_ptEnd.Y >= 0
&& m_ptStart.X <= 254 && m_ptEnd.X <= 254
&& m_ptStart.Y <= 163 && m_ptEnd.Y <= 163)
{
m_ptEnd = new Point(e.X, e.Y);
m_bMouseDown = !m_bMouseDown;
this.imageViewer1.Refresh();
//imageViewer1.Refresh
}
else
{
m_ptEnd = m_ptStart;
m_bMouseDown = !m_bMouseDown;
this.imageViewer1.Refresh();
}
void ImageViewer1Paint(object sender, PaintEventArgs e)
{
if (m_ptStart.Equals(m_ptEnd)) return;
//画矩形加上以下六行
if (m_ptEnd.X - m_ptStart.X < 0 || m_ptEnd.Y - m_ptStart.Y < 0)
{
return;
}
e.Graphics.DrawRectangle(System.Drawing.Pens.Blue, m_ptStart.X, m_ptStart.Y, m_ptEnd.X - m_ptStart.X, m_ptEnd.Y - m_ptStart.Y);
}
|