Reputation: 340
I have a picturebox1 -> Button -> picturebox2
all three are in a consecutive layer so which I want is that picturebox2
should be appear within the button when I debug the program.
My code is,
public Form1()
{
InitializeComponent();
picturebox2.parent = button;
picturebox.backcolor = color.transparent;
}
I am using .jpg for picturebox1
and a .png for picturebox2
but its not appearing. I mean the picture of picturebox2
should appear above the button.
Upvotes: 2
Views: 1956
Reputation: 54463
You need to nest all 3 controls.
You also need to correct the Location
of the nested controls or else they keep the original location, which are relative to their original parents, probably to the form, and not to their new parents!!
This should work better:
public Form1()
{
InitializeComponent();
button.Parent = picturebox;
picturebox2.Parent = button;
picturebox.BackColor = Color.Transparent;
button.Location = new Point(1,2); // or whatever you want!!
picturebox2.Location = new Point(3,4); // or whatever you want!!
}
You may also want to consider simply using the Image
and/or the BackGroundImage
properties of the Button
..
Note: If you want your Button
to let the bottom PictureBox
shine through you need to not only set its Color
but also it's FlatStyle
to Flat
!
Upvotes: 4