社区
C#
帖子详情
C#在pictureBox图像上面画小矩形框
困爆
2016-12-04 03:15:46
界面上面是两个pictureBox,我需要用鼠标在上面画矩形框,可以画多个。
我现在可以在上面画,但是我在另外一个上面画的时候,另外一个界面上面的框就会消失,我不知道怎么回事。
我现在不知道如何做了,有做过类似的大神请帮帮忙,非常感谢,比较急。万分感谢。
...全文
3071
3
打赏
收藏
C#在pictureBox图像上面画小矩形框
界面上面是两个pictureBox,我需要用鼠标在上面画矩形框,可以画多个。 我现在可以在上面画,但是我在另外一个上面画的时候,另外一个界面上面的框就会消失,我不知道怎么回事。 我现在不知道如何做了,有做过类似的大神请帮帮忙,非常感谢,比较急。万分感谢。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
困爆
2016-12-04
打赏
举报
回复
引用 1 楼 xuzuning 的回复:
绘图要在 Paint 事件中进行
下面是我的代码,现在就是一边可以画矩形可以,我用鼠标在另外一个pictureBox上面拉矩形出来的时候,另外一边的所有矩形就消失了。如果可以麻烦你可以帮我看看吗,真的非常非常感谢您! private void IM0001_Load(object sender, EventArgs e) { #region[画矩形] bmsave = new Bitmap(this.picBefore.Width, this.picBefore.Height); g = Graphics.FromImage(bmsave); gform = picBefore.CreateGraphics(); bmsaveAfter = new Bitmap(this.picAfter.Width, this.picAfter.Height); g1 = Graphics.FromImage(bmsaveAfter); gform1 = picAfter.CreateGraphics(); this.event_Registered(); } private void event_Registered() { this.MouseDown += picBefore_MouseDown; this.MouseUp += picBefore_MouseUp; this.MouseMove += picBefore_MouseMove; } protected override void OnPaint(PaintEventArgs e) { //重绘时显示bitmap base.OnPaint(e); gform.DrawImage(this.bmsave, new Point(0, 0)); } private void picBefore_MouseDown(object sender, MouseEventArgs e) { //记录开始点 this.mousedown = true; this.startpoint = e.Location; } private void picBefore_MouseMove(object sender, MouseEventArgs e) { //记录结束点。绘制到窗口上 if (mousedown) { this.endpoint = e.Location; this.Refresh(); gform.DrawImage(this.bmsave, new Point(0, 0)); Rectangle rect = new Rectangle(); this.rect_play(ref rect, "before"); gform.DrawRectangle(new Pen(Color.Red), rect); } } private void picBefore_MouseUp(object sender, MouseEventArgs e) { //记录结束点。绘制到bitmap上 this.endpoint = e.Location; this.mousedown = false; Rectangle rect = new Rectangle(); this.rect_play(ref rect, "before"); g.DrawRectangle(new Pen(Color.Red), rect); gform.DrawImage(this.bmsave, new Point(0, 0)); } #endregion private void rect_play(ref Rectangle rect, string Picflag) { if (Picflag == "before") { //根据两个点确定矩形的左上角点Location if (this.startpoint.X > this.endpoint.X && this.startpoint.Y < this.endpoint.Y)// { rect.Location = new Point(this.endpoint.X, this.startpoint.Y); } else if (this.startpoint.X < this.endpoint.X && this.startpoint.Y > this.endpoint.Y) { rect.Location = new Point(this.startpoint.X, this.endpoint.Y); } else if (this.startpoint.X > this.endpoint.X && this.startpoint.Y > this.endpoint.Y) { rect.Location = this.endpoint; } else { rect.Location = this.startpoint; } //获取两点的X,Y距离 rect.Width = Math.Abs(this.startpoint.X - this.endpoint.X); rect.Height = Math.Abs(this.startpoint.Y - this.endpoint.Y); if (rect.Width == 0 && rect.Height == 0) { //防止误点的时候进行绘制 } else if (rect.Width == 0) { rect.Width = 1; } else if (rect.Height == 0) { rect.Height = 1; } } }
_明月
2016-12-04
打赏
举报
回复
引用 1 楼 xuzuning 的回复:
绘图要在 Paint 事件中进行
你好,你能够给我讲一讲C#.Net中的框架又是怎么一回事么?
xuzuning
2016-12-04
打赏
举报
回复
绘图要在 Paint 事件中进行
C#
中在
picturebox
中实时画
矩形框
C#
中在
picturebox
中实时画
矩形框
C#
pictureBox
绘制
矩形框
重写
pictureBox
相关事件,支持在
pictureBox
上绘制多
矩形框
,以及选中绘制框,选中后支持边框拉伸。
c#
在
pictureBox
控件上绘制
矩形框
,鼠标点击可拖拽,伸缩
winform在
pictureBox
控件上绘制
矩形框
,鼠标点击可拖拽,伸缩
C#
中在
pictureBox
1中实时画
矩形框
.
C#
中在
pictureBox
1中实时画
矩形框
.
C#
实现在
picturebox
内画矩形,并将局部图片放大 源码
C#
实现在
picturebox
内画矩形,并将
矩形框
内选中的局部图片放大显示 源码
C#
111,097
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章