使用GDI+绘图时的一个有关问题

使用GDI+绘图时的一个问题
在使用GDI+绘图时使用了双缓冲,虽然绘制的时候不会出现闪烁,但是莫名其妙的是在你不做任何操作的时候Form_Paint事件居然会触发,导致了界面会出现闪烁,代码如下:
VB code

Option Explicit

Private Sub Form_Load()
    InitGDIPlus
    Timer1.Interval = 1
    Timer1.Enabled = True
End Sub

Private Sub Form_Paint()
    Debug.Print Time & ":paint"
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    TerminateGDIPlus
End Sub

Private Sub Timer1_Timer()
    Dim gpsMemory As Long
    Dim bmpMemory As Long
    Dim bmpBackGround As Long
    Dim bmpMan As Long
    Dim bmpCompass As Long
    Dim Graphics As Long
    
    GdipCreateBitmapFromFile StrPtr("d:\2.jpg"), bmpBackGround
    GdipCreateBitmapFromFile StrPtr("d:\1.jpg"), bmpMan
    GdipCreateBitmapFromFile StrPtr("d:\compass.png"), bmpCompass
    
    GdipCreateBitmapFromScan0 Me.ScaleWidth, Me.ScaleHeight, 0, GpPixelFormat.PixelFormat32bppARGB, ByVal 0, bmpMemory
    GdipGetImageGraphicsContext bmpMemory, gpsMemory
'    GdipSetSmoothingMode gpsMemory, SmoothingModeAntiAlias

    GdipDrawImageRectI gpsMemory, bmpBackGround, 0, 0, Me.ScaleWidth, Me.ScaleHeight
    GdipDrawImageI gpsMemory, bmpMan, 0, 0
    GdipDrawImageI gpsMemory, bmpCompass, 256, 256
    
    GdipCreateFromHWND Me.hwnd, Graphics
    GdipDrawImage Graphics, bmpMemory, 0, 0
    GdipDisposeImage bmpMemory
    GdipDisposeImage bmpBackGround
    GdipDisposeImage bmpMan
    GdipDisposeImage bmpCompass
    GdipDeleteGraphics gpsMemory
    GdipDeleteGraphics Graphics
End Sub


谁来告诉我为神马会触发Form_Paint事件?

------解决方案--------------------
Paint 事件


在一个对象被移动或放大之后,或在一个覆盖该对象的窗体被移开之后,该对象部分或全部暴露时,此事件发生。

语法

Private Sub Form_Paint( )

Private Sub object_Paint([index As Integer])

Paint 事件语法包括下列部分:

部分 描述 
object 一个对象表达式,其值是“应用于”列表中的一个对象。 
index 一个整数,用来唯一地标识一个在控件数组中的控件。 


说明

如果需要代码中各种图形方法的输出,则 Paint 事件过程就很有用。使用 Paint 过程,可以确保这样的输出在必要时能被重绘。

使用 Refresh 方法时,Paint 事件即被调用。如果 AutoRedraw 属性被设置为 True,重新绘图会自动进行,于是就不需要 Paint 事件。

如果 ClipControls 属性被设置为 False,在 Paint 事件过程中的绘图方法仅影响该窗体中新暴露的区域;否则,绘图方法将在该窗体未被控件覆盖的所有区域。( Image、Label、Line 和 Shape 控件除外。)

在 Resize 事件过程中使用 Refresh 方法可在每次调整窗体大小时强制对整个对象进行。

注意 对某些任务使用 Paint 事件过程能导致一个层叠事件。通常来说,在下列情况下,要避免用 Paint 事件过程: 

移动一个窗体或控件,或者是调整其大小。


对影响大小或外观的任何变量进行改变,如:设置对象的 BackColor 属性等。


调用 Refresh 方法。 
对上述这些任务来说,Resize 事件可能更为合适。