-
Oct 14th, 2017, 04:00 PM
#1
Thread Starter
Addicted Member
PictureBox Inside a Panel That is Inside a TabControl TabPage
Hi,
I created a PictureBox inside a Panel that is in a TabPage of a TabControl. The problem is that when I do the BringToFront() command the PictureBox will always stays in the front and wont hide when a different TabPage is selected. Here is the code I'm using to test this part of the program. Any help is greatly appreciated. I suspect that the problem has something to do with the Parent declaration highlighted in red below.
Thanks,
Robert
Code:
Public SquarePic As PictureBox
SquarePic = New PictureBox
SquarePic.Name = "SquareTesting1"
SquarePic.Image = Image.FromFile(Application.StartupPath & "\images\BlackSquare.bmp")
SquarePic.Parent = pnlSquarePanel
SquarePic.Location = New Point(10,10)
SquarePic.Visible = True
Me.Controls.Add(SquarePic)
SquarePic.BringToFront()
-
Oct 14th, 2017, 06:49 PM
#2
Re: PictureBox Inside a Panel That is Inside a TabControl TabPage
Code:
Me.Controls.Add(SquarePic)
This more or less does the same thing as setting Parent. When you do this, you remove the picture box from the panel and reparent it under the form.
That said, most people don't muck with the Parent property as messing with the Controls collection is a little more intuitive. So replace the line that sets the Parent property with:
Code:
pnlSquarePanel.Controls.Add(SquarePic)
...and delete the line that adds it to the form.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Oct 14th, 2017, 07:15 PM
#3
Thread Starter
Addicted Member
Re: PictureBox Inside a Panel That is Inside a TabControl TabPage
Hi, thanks for your explanation. Unfortunately, with the new code below the PictureBox doesn't show at all. With the previous code the PictureBox was showing on top of every TabPage. Now, it doesn't show at all.
Code:
Public SquarePic As PictureBox
SquarePic = New PictureBox
SquarePic.Name = "SquareTesting1"
SquarePic.Image = Image.FromFile(Application.StartupPath & "\images\BlackSquare.bmp")
pnlSquarePanel.Controls.Add(SquarePic)
SquarePic.Location = New Point(10,10)
SquarePic.Visible = True
SquarePic.BringToFront()
-
Oct 14th, 2017, 09:45 PM
#4
Re: PictureBox Inside a Panel That is Inside a TabControl TabPage
Firstly, there should be no need to set the Visible property or call BringToFront. True is the default value for the Visible property and BringToFront can only be useful if the PictureBox overlaps other controls.
As for not being able to see the PictureBox, if you're adding the PictureBox to the Panel and you can't see the PictureBox then that means that you can't see the Panel. I don't know how pnlSquarePanel was added or configured but if it's visible to the user then any control you Add to it will also be visible. You can prove that to yourself with a test project. I just create a Windows Forms app project, added a TabControl and a Button and then added a Panel to the second TabPage. I set the Dock property of the Panel to Fill and then added this code:
vb.net Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim pb As New PictureBox pb.BorderStyle = BorderStyle.FixedSingle Panel1.Controls.Add(pb) End Sub
If you run the project, select the second tab and click the Button, you'll see the PictureBox appear. If you don't then something on your system is broken.
-
Oct 15th, 2017, 03:17 PM
#5
Thread Starter
Addicted Member
Re: PictureBox Inside a Panel That is Inside a TabControl TabPage
Thank you guys. Yes, you are right. The problem that I was having was with the declaration SquarePic.Location = New Point(......). I wasn't doing it correctly.
-
Oct 15th, 2017, 05:17 PM
#6
Re: PictureBox Inside a Panel That is Inside a TabControl TabPage
Originally Posted by VB-MCU-User
Thank you guys. Yes, you are right. The problem that I was having was with the declaration SquarePic.Location = New Point(......). I wasn't doing it correctly.
That's odd because that line looks OK to me, although it should have been before the control was added.
That said, there's not a declaration. For it to be a declaration, you'd have to be declaring something, which you're not. That line creates a Point value and assigns it to a property. A declaration would require a Dim keyword.
-
Oct 15th, 2017, 05:35 PM
#7
Thread Starter
Addicted Member
Re: PictureBox Inside a Panel That is Inside a TabControl TabPage
No, the line that I actually used wasn't SquarePic.Location = New Point(10,10) with the 10,10. I used something else instead of the 10,10 that was messing everything up. Thanks.
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
|