谢谢
9 个解决方案
#1
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Sub command2_Click()
keybd_event 18, 0, 0, 0
keybd_event vbKeySnapshot, 0&, 0&, 0&
DoEvents
keybd_event 18, 0, KEYEVENTF_KEYUP, 0
SavePicture Clipboard.GetData, "c:\abc.bmp"
End Sub
#2
上面的大哥,能做一下说明不,比方说:那个是左上角坐标,右下角坐标之类的
#3
我想在程序中用一条语句来把窗体上面的图形保存下来,形成一个图片文件
而且想指定坐标截图
而且想指定坐标截图
#4
一条语句?
偶办不到。
估计要好几条。 -_-!!
偶办不到。
估计要好几条。 -_-!!
#5
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
Me.Line (10, 10)-(100, 100), vbRed, BF
SavePicture Me.Image, "c:\temp.bmp"
End Sub
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
Me.Line (10, 10)-(100, 100), vbRed, BF
SavePicture Me.Image, "c:\temp.bmp"
End Sub
#6
http://www.china-askpro.com/msg2/qa05.shtml
#7
标准模块:
Form1的窗体模块:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
''''GDI函数:
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 Const SRCCOPY = &HCC0020 '''' (DWORD) dest = source
''''创建一个memory DC:
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
''''在memory中建立一个位图:
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
''''把一个GDI对象放入DC,返回原先的那个:
Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
''''删除GDI对象:
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
''''剪贴板函数:
Private Declare Function OpenClipboard Lib "USER32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "USER32" () As Long
Private Declare Function SetClipboardData Lib "USER32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
'Public Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
Private Declare Function EmptyClipboard Lib "USER32" () As Long
Private Const CF_BITMAP = 2
Public Function CopyEntirePicture(ByRef objFrom As Object) As Boolean
Dim lhDC As Long
Dim lhBMP As Long
Dim lhBMPOld As Long
''''在内存中建立一个指向我们将要复制对象的DC:
lhDC = CreateCompatibleDC(objFrom.hDC)
If (lhDC <> 0) Then
''''建立一张指向将要复制对象的位图:
lhBMP = CreateCompatibleBitmap(objFrom.hDC, objFrom.ScaleWidth \ Screen.TwipsPerPixelX, objFrom.ScaleHeight \ Screen.TwipsPerPixelY)
If (lhBMP <> 0) Then
''''把位图选入我们刚才建立的DC中,并贮存原先在那里的老位图:
lhBMPOld = SelectObject(lhDC, lhBMP)
''''把objFrom的内容复制到建立的位图里:
BitBlt lhDC, 0, 0, objFrom.ScaleWidth \ Screen.TwipsPerPixelX, objFrom.ScaleHeight \ Screen.TwipsPerPixelY, objFrom.hDC, 0, 0, SRCCOPY
''''恢复DC中的内容:
SelectObject lhDC, lhBMPOld
''''现在把位图装入剪贴板:
EmptyClipboard
OpenClipboard 0
SetClipboardData CF_BITMAP, lhBMP
CloseClipboard
''''我们在这里不用删除建立的位图——
''''它现在属于剪贴板,当剪贴板变化时,Windows将为我们删除它。
End If
''''清除刚才建立的DC:
DeleteObject lhDC
End If
End Function
Form1的窗体模块:
'窗体Form1上放一个图片框Picture1,二个命令按钮Command1,Command2
Option Explicit
Private Sub Command1_Click() '窗体Form1整体复制到剪贴板
CopyEntirePicture Form1
End Sub
Private Sub Command2_Click()
'Picture1.Picture = Clipboard.GetData(vbCFBitmap)'从剪贴板中显示图像到Picture1中
SavePicture Clipboard.GetData(vbCFBitmap), "C:\窗体Form1的图片.bmp" '剪贴板图像直接保存为文件
End Sub
Private Sub Form_Load()
Dim i As Long
Command1.Caption = "抓取窗体到剪贴板"
Command2.Caption = "剪贴板图像保存到文件中"
Picture1.AutoRedraw = True
''''在PictureBox中画些东西:
With Picture1.Font
.Name = "Arial"
.Bold = True
.Size = 12
End With
For i = 1 To 20
Picture1.ForeColor = QBColor(i Mod 15)
Picture1.Print "http://www.archtide.com"
Next i
End Sub
#8
我楼上这个,不仅可以保存窗体,还可以保存窗体上的所有控件及内容!
#9
楼上已经解决!
#1
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Sub command2_Click()
keybd_event 18, 0, 0, 0
keybd_event vbKeySnapshot, 0&, 0&, 0&
DoEvents
keybd_event 18, 0, KEYEVENTF_KEYUP, 0
SavePicture Clipboard.GetData, "c:\abc.bmp"
End Sub
#2
上面的大哥,能做一下说明不,比方说:那个是左上角坐标,右下角坐标之类的
#3
我想在程序中用一条语句来把窗体上面的图形保存下来,形成一个图片文件
而且想指定坐标截图
而且想指定坐标截图
#4
一条语句?
偶办不到。
估计要好几条。 -_-!!
偶办不到。
估计要好几条。 -_-!!
#5
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
Me.Line (10, 10)-(100, 100), vbRed, BF
SavePicture Me.Image, "c:\temp.bmp"
End Sub
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
Me.Line (10, 10)-(100, 100), vbRed, BF
SavePicture Me.Image, "c:\temp.bmp"
End Sub
#6
http://www.china-askpro.com/msg2/qa05.shtml
#7
标准模块:
Form1的窗体模块:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
''''GDI函数:
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 Const SRCCOPY = &HCC0020 '''' (DWORD) dest = source
''''创建一个memory DC:
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
''''在memory中建立一个位图:
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
''''把一个GDI对象放入DC,返回原先的那个:
Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
''''删除GDI对象:
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
''''剪贴板函数:
Private Declare Function OpenClipboard Lib "USER32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "USER32" () As Long
Private Declare Function SetClipboardData Lib "USER32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
'Public Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
Private Declare Function EmptyClipboard Lib "USER32" () As Long
Private Const CF_BITMAP = 2
Public Function CopyEntirePicture(ByRef objFrom As Object) As Boolean
Dim lhDC As Long
Dim lhBMP As Long
Dim lhBMPOld As Long
''''在内存中建立一个指向我们将要复制对象的DC:
lhDC = CreateCompatibleDC(objFrom.hDC)
If (lhDC <> 0) Then
''''建立一张指向将要复制对象的位图:
lhBMP = CreateCompatibleBitmap(objFrom.hDC, objFrom.ScaleWidth \ Screen.TwipsPerPixelX, objFrom.ScaleHeight \ Screen.TwipsPerPixelY)
If (lhBMP <> 0) Then
''''把位图选入我们刚才建立的DC中,并贮存原先在那里的老位图:
lhBMPOld = SelectObject(lhDC, lhBMP)
''''把objFrom的内容复制到建立的位图里:
BitBlt lhDC, 0, 0, objFrom.ScaleWidth \ Screen.TwipsPerPixelX, objFrom.ScaleHeight \ Screen.TwipsPerPixelY, objFrom.hDC, 0, 0, SRCCOPY
''''恢复DC中的内容:
SelectObject lhDC, lhBMPOld
''''现在把位图装入剪贴板:
EmptyClipboard
OpenClipboard 0
SetClipboardData CF_BITMAP, lhBMP
CloseClipboard
''''我们在这里不用删除建立的位图——
''''它现在属于剪贴板,当剪贴板变化时,Windows将为我们删除它。
End If
''''清除刚才建立的DC:
DeleteObject lhDC
End If
End Function
Form1的窗体模块:
'窗体Form1上放一个图片框Picture1,二个命令按钮Command1,Command2
Option Explicit
Private Sub Command1_Click() '窗体Form1整体复制到剪贴板
CopyEntirePicture Form1
End Sub
Private Sub Command2_Click()
'Picture1.Picture = Clipboard.GetData(vbCFBitmap)'从剪贴板中显示图像到Picture1中
SavePicture Clipboard.GetData(vbCFBitmap), "C:\窗体Form1的图片.bmp" '剪贴板图像直接保存为文件
End Sub
Private Sub Form_Load()
Dim i As Long
Command1.Caption = "抓取窗体到剪贴板"
Command2.Caption = "剪贴板图像保存到文件中"
Picture1.AutoRedraw = True
''''在PictureBox中画些东西:
With Picture1.Font
.Name = "Arial"
.Bold = True
.Size = 12
End With
For i = 1 To 20
Picture1.ForeColor = QBColor(i Mod 15)
Picture1.Print "http://www.archtide.com"
Next i
End Sub
#8
我楼上这个,不仅可以保存窗体,还可以保存窗体上的所有控件及内容!
#9
楼上已经解决!