怎样做到messagebox不覆盖picturebox的内容?

yinduasan111 2003-08-23 04:09:37
Dim oldpt As New Point(100, 100)
Dim newpt As New Point(500, 100)
Public Cache As New Bitmap(500, 500)
Public CacheG As Graphics

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DrawImage()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MessageBox.Show("The calculations are complete", "msg", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End Sub

Private Function DrawImage()
PictureBox1.CreateGraphics.DrawLine(New Pen(Color.Black, 1), oldpt, newpt)
End Function

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
DrawImage()
End Sub

以上是我按照这个论坛里一篇帖子里抄来的,Button1_Click在PictureBox1里画一条直线,Button2_Click弹出 messagebox。虽然我发现在移动messagebox时候没有问题,但是如果最后点击OK的时候如果messagebox还在直线上,那么messagebox消失以后,直线被遮盖的部份也随着消失了。
...全文
41 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Brunhild 2003-08-23
  • 打赏
  • 举报
回复
因为DrawImage绘画的直线并没有重画的机制,一但刷新所在区域就没有了。解决方法有:
1. 在picturebox的paint事件中重画直线
2. 将直线画在image中,用picturebox显示此image
citylamp 2003-08-23
  • 打赏
  • 举报
回复
那就再添加MessageBox()按下OK以后的重画嘛。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MessageBox.Show("The calculations are complete", "msg", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Me.Refresh() ‘先清空
DrawImage() ‘再重画
End Sub
Brunhild 2003-08-23
  • 打赏
  • 举报
回复
改动不大,在DrawImage中改就可以了:
With (Me.PictureBox1)
If Me.PictureBox1.Image Is Nothing Then
Dim bm As New System.Drawing.Bitmap(.Width, .Height)
.Image = bm
End If

Dim graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(.Image)
graphics.DrawLine(System.Drawing.Pens.Black, 0, 0, 100, 100)
End With
yinduasan111 2003-08-23
  • 打赏
  • 举报
回复
那怎么把直线画在image里呢,如果原来之间是在picturebox里画的,程序是否需要很大改动呢?

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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