关于画图的2个问题

bao0614 2007-10-09 07:39:40
1,当选择form1的按钮时怎样可以在form2的picturebox中画图?应该怎样创建picturebox的grahics对象?

2,怎样实现图像的整体、部分选取,复制?并且在选取时被选中的区域有个虚线框,在复制完后虚线框消失?

请高手们不吝赐教 最好有代码 谢谢!
...全文
99 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
banping 2007-10-12
  • 打赏
  • 举报
回复
上面 说得很详细了,虚线筐就是用鼠标事件,draw一个矩形出来。然后不用的时候再重新画这个图片。
北京的雾霾天 2007-10-10
  • 打赏
  • 举报
回复
继承PictureBox控件,然后添加类似如下的代码:



//鼠标拖动的虚框实现
private Point m_StartPoint;
private Point m_LastPoint;

protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
this.m_StartPoint = e.Location;
m_LastPoint = this.m_StartPoint;
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
Point endPoint = e.Location;
int l = m_LastPoint.X > this.m_StartPoint.X ? this.m_StartPoint.X : m_LastPoint.X;
int t = m_LastPoint.Y > this.m_StartPoint.Y ? this.m_StartPoint.Y : m_LastPoint.Y;
int r = m_LastPoint.X > this.m_StartPoint.X ? m_LastPoint.X : this.m_StartPoint.X;
int b = m_LastPoint.Y > this.m_StartPoint.Y ? m_LastPoint.Y : this.m_StartPoint.Y;

Rectangle rect = Rectangle.FromLTRB(l, t, r, b);
ControlPaint.DrawReversibleFrame(this.RectangleToScreen(rect), SystemColors.Highlight, FrameStyle.Dashed);
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
Point endPoint = e.Location;
int l = m_LastPoint.X > this.m_StartPoint.X ? this.m_StartPoint.X : m_LastPoint.X;
int t = m_LastPoint.Y > this.m_StartPoint.Y ? this.m_StartPoint.Y : m_LastPoint.Y;
int r = m_LastPoint.X > this.m_StartPoint.X ? m_LastPoint.X : this.m_StartPoint.X;
int b = m_LastPoint.Y > this.m_StartPoint.Y ? m_LastPoint.Y : this.m_StartPoint.Y;

Rectangle rect = Rectangle.FromLTRB(l, t, r, b);
ControlPaint.DrawReversibleFrame(this.RectangleToScreen(rect), SystemColors.Highlight, FrameStyle.Dashed);

int _l = endPoint.X > this.m_StartPoint.X ? this.m_StartPoint.X : endPoint.X;
int _t = endPoint.Y > this.m_StartPoint.Y ? this.m_StartPoint.Y : endPoint.Y;
int _r = endPoint.X > this.m_StartPoint.X ? endPoint.X : this.m_StartPoint.X;
int _b = endPoint.Y > this.m_StartPoint.Y ? endPoint.Y : this.m_StartPoint.Y;

Rectangle _rect = Rectangle.FromLTRB(_l, _t, _r, _b);
ControlPaint.DrawReversibleFrame(this.RectangleToScreen(_rect), SystemColors.Highlight, FrameStyle.Dashed);
m_LastPoint = endPoint;
}
}


在Form1中生成Form2的PictureBox的Graphics,可以在Form2中编写一个方法:
public Graphics GetGraphics()
{
return this.PictureBox1.CreateGraphics();
}

在Form1中添加Form2的实例的引用,通过实例引用调用方法:

Graphics g = this.form2.GetGraphics();
...
g.Dispose();
jason909 2007-10-10
  • 打赏
  • 举报
回复
要实现功能很多不是技术问题,而是设计的问题,要先做好设计
真相重于对错 2007-10-09
  • 打赏
  • 举报
回复
使用消息,或者事件

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧