Solved

VB6 - Snapshot of a label in a form

Posted on 2013-06-30
5
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 48

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…

687 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