为什么我会收到“幽灵线"?在形式上? [英] Why do I get "ghost lines" on form?
本文介绍了为什么我会收到“幽灵线"?在形式上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常特殊的问题.
使用System.Drawing.Graphics,我在表单上创建了几个矩形.
看起来大约5秒钟很好,然后在矩形的上方和左侧放置了由矩形组成的副本".
如果我最小化并还原,鬼影"矩形将消失.
I have a very peculiar problem.
Using System.Drawing.Graphics I create several rectangles on a form.
It looks fine for about 5 seconds, then there are "copies" made of the rectangles, placed higher up and to the left on the form.
If I minimize and restore, the "ghost" rectangles are gone.
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Black, 2)
Dim Rect1 As New System.Drawing.Rectangle(13, 295, 416, 259)
formGraphics.DrawRectangle(myPen, Rect1)
Dim Rect2 As New System.Drawing.Rectangle(13, 295 + 259, 416, 230)
formGraphics.DrawRectangle(myPen, Rect2)
Dim Rect3 As New System.Drawing.Rectangle(13 + 416, 295, 330, 180)
formGraphics.DrawRectangle(myPen, Rect3)
Dim Rect4 As New System.Drawing.Rectangle(13 + 416, 295 + 180, 330, 145)
formGraphics.DrawRectangle(myPen, Rect4)
Dim Rect5 As New System.Drawing.Rectangle(13 + 416, 295 + 180 + 145, 330, 164)
formGraphics.DrawRectangle(myPen, Rect5)
Dim Rect6 As New System.Drawing.Rectangle(13, 295, 416, 259)
formGraphics.DrawRectangle(myPen, Rect6)
formGraphics.Dispose()
myPen.Dispose()
End Sub
推荐答案
尝试使用e.Graphics在表单上进行绘制.
Try using the e.Graphics for drawing on the form.
Dim g As Graphics = e.Graphics
更多信息:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx [ ^ ]
祝你好运!
More info:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx[^]
Good luck!
当该对象的一部分无效或刷新时,将调用控件或窗体的绘制,这仅意味着当Windows认为屏幕的该部分不再存在时通过将WM_PAINT消息传递到表单,或通过请求表单发生的表单本身上的代码来实现准确无误.
当我们调整窗体大小或使其最小化或最大化form_paint事件时,将调用
.
现在您已经说过大约5秒钟看起来还不错".在那5分钟之后您进行了任何活动吗?
The paint of a control, or form is called when a portion of that object is invalidated or refreshed, which simply means that when windows thinks that part of the screen is no longer accurate, either by passing the WM_PAINT message to the form, or by code on the form itself requesting that it happen.
when we resize form or make it minimize or maximize form_paint event get''s called.
now you have said "It looks fine for about 5 seconds". have you did any activities after that 5 min.
这篇关于为什么我会收到“幽灵线"?在形式上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文