利用VB如何将picturebox中的TDBGrid保存成一张图片
展开全部
两个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
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
追问
不好意思,我是初学者,再问一下
Me.Left / 15 + 8 + Picture1.Left, Me.Top / 15 + 30 + Me.Picture1.Top这两句怎么理解?
Me.ScaleMode = 3
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
这三句为什么要赋值为3
追答
赋值为3,是让它们的坐标度量单位按照像素来计算
Me.Left / 15 + 8 + Picture1.Left 窗口左边坐标+Picture1的左边=Picture1在屏幕中的绝对位置,之所以除以15,是为了对应于像素单位,而不是堤,加8个像素是为了去掉Picture1的边框宽度
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询