Solved

VB6 - Snapshot of a label in a form

Posted on 2013-06-30
5
340 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 47

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

696 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