-
Jun 17th, 2024, 08:39 AM
#1
Thread Starter
Fanatic Member
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?
-
Jun 17th, 2024, 08:43 AM
#2
Re: Label Hidden Behind PictureBox
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
-
Jun 17th, 2024, 08:59 AM
#3
Thread Starter
Fanatic Member
Re: Label Hidden Behind PictureBox
I tried
Label1.ZOrder 0 'bring to front
Still obscured
-
Jun 17th, 2024, 09:05 AM
#4
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.
-
Jun 17th, 2024, 09:19 AM
#5
Thread Starter
Fanatic Member
Re: Label Hidden Behind PictureBox
Understood.
Can a label be placed inside the PictureBox at runtime or must it be done at design time?
-
Jun 17th, 2024, 11:16 AM
#6
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).
-
Jun 17th, 2024, 02:12 PM
#7
Thread Starter
Fanatic Member
Re: Label Hidden Behind PictureBox
That's perfect yes!
Thank you Sam
-
Jun 17th, 2024, 02:55 PM
#8
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).
-
Jun 17th, 2024, 02:56 PM
#9
Fanatic Member
Re: Label Hidden Behind PictureBox
Why don't you just place a label onto the picturebox. Works for me (VB5).
-
Jun 17th, 2024, 03:33 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|