Reputation: 447
I have a MainForms.cs with Ribbon, I want to put a transparent PictureBox on the top right of the ribbon (The PictureBox represent my logo).
Code :
InitializeComponent();
pictureBox1.Parent = ribbon1;
Until here all is working great.
When I resize my Form, the PictureBox disappears.
On the OnPaint fonction i reset all setting like that :
protected override void OnPaint(PaintEventArgs pe)
{
this.Activate();
pictureBox1.Visible = true;
pictureBox1.Show();
pictureBox1.BringToFront();
}
But nothing makes the Picturebox appear. Please, can you tell me what i missed.
Upvotes: 2
Views: 1418
Reputation: 54522
I downloaded the DLL that you are using and created a small test example. What I noticed is the Parent property of the PictureBox was set to null. By adding the Parent back to the Picturebox in the OnPaint event I was able to get it working if the size of the Form was growing, but would disappear when the Form size was reduced. When I put the same code in the OnResize EventHandler it works like you would expect.
public partial class Form1 : Form
{
PictureBox pictureBox1 = new PictureBox();
public Form1()
{
InitializeComponent();
pictureBox1.Image = Image.FromFile(@"C:\temp\test.jpg");
pictureBox1.Parent = ribbon1;
pictureBox1.Location = new Point(this.Width-pictureBox1.Width,10);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (pictureBox1.Parent == null)
{
pictureBox1.Parent = ribbon1;
pictureBox1.Visible = true;
pictureBox1.Location = new Point(this.Width - pictureBox1.Width, 10);
}
}
}
Upvotes: 2