Results 1 to 10 of 10

Thread: Label Hidden Behind PictureBox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    666

    Label Hidden Behind PictureBox

    Hello,

    I am trying to place a label overtop a PictureBox but it will not show.

    To demonstrate
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        
        Form1.ScaleMode = vbPixels
        
        Picture1.Appearance = 0
        Picture1.Width = 100
        Picture1.Height = 100
        Picture1.Left = 40
        Picture1.Top = 40
        
        Label1.Width = 50
        Label1.Height = 25
        Label1.Left = Picture1.Left
        Label1.Top = Picture1.Top - 8
        Label1.Caption = "Test"
    
    End Sub
    The word Test is partially obscured by the PictureBox.

    How can I fix this?

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,611

    Re: Label Hidden Behind PictureBox

    Z-Order?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    666

    Re: Label Hidden Behind PictureBox

    I tried

    Label1.ZOrder 0 'bring to front

    Still obscured

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,326

    Re: Label Hidden Behind PictureBox

    VB6 has TWO z-order planes. Basically, the Image and Label control are on one (the lower one), and all other controls are on the other (the higher one). And, everything on that lower z-order plane is always under the higher z-order plane.

    However, you can put a label inside of a PictureBox, which often fixes the problem.

    Also, just to make a couple of other points. Certain user defined controls can also be on the lower z-order plane. And also, controls on this lower z-order plane do not have hWnd handles. Basically, they're drawn directly onto the form (or whatever its container is) when that form is shown.

    Another option that people often use in this situation is a locked TextBox (which will be on the higher z-order plane).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    666

    Re: Label Hidden Behind PictureBox

    Understood.

    Can a label be placed inside the PictureBox at runtime or must it be done at design time?

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,322

    Re: Label Hidden Behind PictureBox

    Will this 'trick' do it for you? (Using an array)

    Code:
    Option Explicit
    'Add a LABEL array (label(0)) to the FORM in the IDE
    'Set its visible property to FALSE
    'Set a caption to your Label(0)
    'Add a PICTUREBOX to the FORM
    'Add a COMMANDBUTTON to the form
    'CODE:
    Private Sub Command1_Click()
            Load Label1(1)
            Label1(1).Caption = Label1(0).Caption
            With Label1(1)
                    'Move this instance of the label array into Picture1
                    Set .Container = Picture1
                    .Move 90, 90  'Your choice where.
                    .Visible = True
            End With
    End Sub
    Last edited by SamOscarBrown; Jun 17th, 2024 at 12:48 PM.
    Sam I am (as well as Confused at times).

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    666

    Re: Label Hidden Behind PictureBox

    That's perfect yes!

    Thank you Sam

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,322

    Re: Label Hidden Behind PictureBox

    Welcome....you wanna mark this Thread as Resolved (Menu/Thread Tools)?
    Sam I am (as well as Confused at times).

  9. #9
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    898

    Re: Label Hidden Behind PictureBox

    Why don't you just place a label onto the picturebox. Works for me (VB5).

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,322

    Re: Label Hidden Behind PictureBox

    They most certainly can (and I would have), but I was just answering their question in post # 5.

    Maybe there is a reason....Maybe they want user to see the label on the form first (its visible property would be True), but wants the user to 'move' the label to a picturebox for some unknown reason.
    Sam I am (as well as Confused at times).

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