Michael
Michael

Reputation: 13616

How to programmatically add PictureBox control to the tab page control

How can I programmatically add a PictureBox control to a TabPage control and fit to its size?

Upvotes: 2

Views: 10970

Answers (2)

Dumbo
Dumbo

Reputation: 14112

The code would be look like:

        var pb = new PictureBox();
        pb.Image = Bitmap.FromFile(@"\\filepath");
        pb.Dock = DockStyle.Fill;
        yourTabPage.Controls.Add(pb);

But if your sole purpose for the tab page is displaying an image, you better use the 'BackgroundImage' of the tabpage itself and use its BackgroundImageLayout to maintain image size, this saves a bit of hassel compared to adding a PictureBox

Upvotes: 3

L.B
L.B

Reputation: 116108

PictureBox pb = new PictureBox();
pb.Dock = DockStyle.Fill;
tabPage.Controls.Add(pb);

Upvotes: 6

Related Questions