Solved

VB6 - Snapshot of a label in a form

Posted on 2013-06-30
5
339 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 46

Assisted Solution

by:Martin Liss
Martin Liss earned 100 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 45

Assisted Solution

by:aikimark
aikimark earned 50 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 350 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

840 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