Solved

VB6 - Snapshot of a label in a form

Posted on 2013-06-30
5
334 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 45

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 27

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 27

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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 about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now