Results 1 to 10 of 10

Thread: Labels inside pictureboxs

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    13
    I need to create some buttons where there is a label inside a picturebox. At design time, I have no problems: I create them seperately then cut and paste the label into the picturebox.

    I tried the run-time creation of similar buttons using the
    Load Picture1(i)
    Load Label1(i)

    methods but this makes them seperate and subsequently the text is hidden by the image. How do I fix this?

    I would also like to know how, in general, you put text over pictures.

    Bye
    Elwyn

  2. #2
    Guest
    You need to setthe parent property of the labels to be the picture box, cos they are by default the form.

    Just change the handles I think

    - gaffa

  3. #3
    New Member
    Join Date
    Nov 2000
    Posts
    14

    hmmm....

    I think you can put text over picture boxes by using a text box or label.
    Then after creating the text box/label, just specify the co-ordinates you want it on the picture using the .Move X,Y method.

  4. #4
    Guest
    Sort of.

    Labels a re window less controls (they have no hWnd property), and as such are always last in the ZOrder, so you need to make the paretn of the lable is a container (the pic box in this case)

    - gaffa

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    13
    How do I set the parent property? I tried this and it generated an error.

    Private Sub Command1_Click()
    Load Form1.Picture1(1)
    Load Form1.Label1(1)

    Form1.Picture1(1).Top = 0
    Form1.Picture1(1).Left = 0
    Form1.Picture1(1).Visible = True
    Form1.Label1(1).Left = 0
    Form1.Label1(1).Top = 0
    Form1.Label1(1).Visible = True

    Form1.Label1(1).Parent = Form1.Picture1(1)
    End Sub

    Would I be better off creating my own ActiveX control since it would have encapsulation?

  6. #6
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    Thumbs up TextOut

    How about using the API function TextOut to accomplish this.....

    Code:
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
    
    
    Private Sub Form_Load()
        Picture1.Picture = LoadPicture("C:\Windows\Clouds.bmp")
    End Sub
    
    Private Sub Picture1_Paint()
      Dim lRet As Long
      Dim sDisp As String
      Dim lStrLen As Integer
      Dim iX As Integer, iY As Integer
      
        ' Convert Coordinates to Pixels
        iX = Form1.ScaleX(60, vbTwips, vbPixels)
        iY = Form1.ScaleY(60, vbTwips, vbPixels)
        sDisp = "Clouds" ' Text to display in Picture Box
        lStrLen = Len(sDisp) ' Length of string
        lRet = TextOut(Picture1.hdc, iX, iX, sDisp, lStrLen)
        
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    13
    TextOut seems neat but does it allow the font name, font size (etc) to be set?

    Anyway, I've been working on the ActiveX control version this afternoon.

    My two current problems I have so far are:
    a) that I don't know why the mouseUp event isn't being called after the user releases the mouse button
    b) I don't know how to get the ActiveX component to tell the form what to do when it receives a mouseDown event

  8. #8
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    TextOut uses the current font, font size, font color, etc. when used with a Picture Box or Form.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  9. #9
    Guest
    Or use the Print method.
    Code:
    Private Sub Command1_Click()
        Picture1.ForeColor = vbRed
        Picture1.FontName = "Courier New"
        Picture1.Print "GDFGFD"
    End Sub
    
    Private Sub Command2_Click()
        Picture1.ForeColor = vbBlue
        Picture1.FontName = "Times New Roman"
        Picture1.Print "FDSDSFS"
    End Sub

  10. #10
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    I had the same problem.
    All you have to do is put on in it (before running) you can make in invisible if you want. Then, during runtime:
    Code:
    Load Label(Label.Count)
    Label(Label.Count - 1).Visible = True
    Label(Label.Count - 1).Caption = "Markman is the best!"
    Label(Label.Count - 1).Top = Label(Label.Count - 2).Top _ + Label(Label.Count - 2).Height
    It workd for me.
    You can even put a loop around it:
    Do
    'what it says above
    Loop Until Label.Count = 10
    retired member. Thanks for everything

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width