# Re: 有关sstab上的绘图问题

Posted by 小琳 on July 10, 1999 at 17:41:43:

In Reply to: 有关sstab上的绘图问题 posted by lool on July 10, 1999 at 13:11:43:

: 各位好
: 小地有个问题想请大家帮忙
: 我写了一个程式有用到sstab控制项,在其中一个页签上放了
: picture box和一个commandbuttom ,只要按下commandbuttom 程式就会在picture box上绘图,而我的问题为可以在picture box上绘图,但是只要切换sstab上的页签,原本画好的图就会消失,想请问这有无方法可解决 谢谢

:::在Form里面放入一个SSTab,Command Button及二个Picture
Box物件，至于程式则如下：
Option Explicit

Private Sub Command1_Click()
Picture2.AutoRedraw = True
BitBlt Picture2.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
Picture2.AutoRedraw = False
Picture2.Refresh
End Sub

Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
Picture2.Height = Picture1.Height
Picture2.Width = Picture1.Width
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
Picture1.PSet (x, y)
End If
End Sub

Private Sub SSTab1_Click(PreviousTab As Integer)
If SSTab1.Caption = "Tab 1" Then
Picture1.AutoRedraw = True
BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, vbSrcCopy
Picture1.AutoRedraw = False
Picture1.Refresh
End If
End Sub

新增一个模组，内容如下：
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Follow Ups:

- 小琳的做法不错, 但有更快的方式 Sephiroth 14:26:13 7/12/99 (0)