我爲你做了一個示例項目,在那裏展示了一些onPaint事件。如果你看不到它以這種方式解決,只需更新示例。
問候! ![OnPaint example](https://i.stack.imgur.com/tUvTn.png)
這裏下載: http://www.goldengel.ch/temp/OnPaintExample.zip
Private Sub Button1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
Dim bm As New Bitmap(Me.Button1.Width, Me.Button1.Height, PixelFormat.Format32bppRgb)
Button1.DrawToBitmap(bm, New Rectangle(0, 15, bm.Width -5, bm.Height+2))
Using gr As Graphics = Graphics.FromImage(bm)
gr.DrawString(DateTime.Now.ToLongTimeString, Me.Font, Brushes.Lime, 0, 0)
End Using
Me.PictureBox1.BackgroundImageLayout = ImageLayout.Tile
Me.PictureBox1.BackgroundImage = bm
End Sub
Public Class myTextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.Clear(Color.Yellow)
e.Graphics.DrawString(DateTime.Now.ToLongTimeString, Me.Font, Brushes.Gray, 0, 0)
End Sub
Public Sub New()
SetStyle(ControlStyles.UserPaint, True)
End Sub
End Class
我不完全清楚爲什麼`DrawToBitmap`(`WM_PRINT`消息)是不可接受的爲您使用。你擔心*表演*嗎?繪製位圖不太可能比畫在屏幕上慢。 – 2011-12-17 10:22:11
我需要一個緩衝機制。 DrawToBitmap從頭開始繪製整個控件,而在正常窗口中使用的無效系統只會更新實際更改的區域。 – 2011-12-17 13:00:38