利用VB如何将picturebox中的TDBGrid保存成一张图片

2024-11-06 13:43:58
推荐回答(1个)
回答(1):

两个PictureBox,一个按钮,其中要保存的是Picture1,可以在Picture1中放入其它控件
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private 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
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Sub Command1_Click()
Dim hdc As Long
hdc = GetDC(0)
BitBlt Picture2.hdc, 0, 0, Picture1.Width, Picture1.Height, hdc, Me.Left / 15 + 8 + Picture1.Left, Me.Top / 15 + 30 + Me.Picture1.Top, vbSrcCopy
SavePicture Picture2.Image, "c:\1.bmp"
ReleaseDC 0, hdc
End Sub
Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
End Sub