?
Solved

VB6 - Snapshot of a label in a form

Posted on 2013-06-30
5
Medium Priority
?
349 Views
Last Modified: 2013-07-01
Hi all

I would like to know how i can create a command that would take a snapshot of my label 1 in my form.

Is that possible?

My Label1 position in my form is:
Height:11175
Left: 7230
Top: 240
Width:9855

Thanks for your help
0
Comment
Question by:Wilder1626
5 Comments
 
LVL 50

Assisted Solution

by:Martin Liss
Martin Liss earned 400 total points
ID: 39288772
One way to do it is to write a routine that

1. Sets all controls on the form except for the label to Visible = False
2. Printer.Printform
3. Set all controls to visible that are supposed to be visible
0
 
LVL 46

Assisted Solution

by:aikimark
aikimark earned 200 total points
ID: 39288827
It would be easier to get the text on the label by accessing the label's Caption property
0
 
LVL 28

Accepted Solution

by:
Ark earned 1400 total points
ID: 39288857
Slightly edited to get snapshot into clipboard:
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 Sub Command1_Click()
  CopyLabel Label1, Picture1
End Sub

Private Sub CopyLabel(lbl As Label, pb As PictureBox)
   Dim x As Long, y As Long, w As Long, h As Long
   Dim tpp As Long
   tpp = Screen.TwipsPerPixelX
   x = lbl.Left / tpp
   w = lbl.Width / tpp
   tpp = Screen.TwipsPerPixelY
   y = lbl.Top / tpp
   h = lbl.Height / tpp
   pb.AutoRedraw = True
   BitBlt pb.hDC, 0, 0, w, h, Me.hDC, x, y, vbSrcCopy
   pb.Refresh
   Clipboard.Clear
   Clipboard.SetData pb.Image
End Sub

Open in new window

0
 
LVL 28

Expert Comment

by:Ark
ID: 39288890
Finally - with adjusted size and ability to save to disk:
Private Sub CopyLabel(lbl As Label, _
                      Optional ByVal filePath As String = "")
   Dim x As Long, y As Long, w As Long, h As Long
   Dim tpp As Long
   tpp = Screen.TwipsPerPixelX
   x = lbl.Left / tpp
   w = lbl.Width / tpp
   tpp = Screen.TwipsPerPixelY
   y = lbl.Top / tpp
   h = lbl.Height / tpp
   With Picture1
      .Width = lbl.Width
      .Height = lbl.Height
      .AutoRedraw = True
      .Appearance = 0
      .BorderStyle = 0
      BitBlt .hDC, 0, 0, w, h, Me.hDC, x, y, vbSrcCopy
      .Refresh
      Clipboard.Clear
      Clipboard.SetData .Image
      If filePath <> "" Then
         SavePicture .Image, filePath
      End If
   End With
End Sub

Open in new window

Calling (copy label image into clipboard and save it in c:\test.bmp):
'Add Picture1 (picturebox) on form, make it invisible (visible=false)
Private Sub Command1_Click()
  CopyLabel Label1, "c:\test.bmp"
End Sub

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39289826
Hi All, thanks for your help

now it's working great
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question