Reputation: 13616
How can I programmatically add a PictureBox
control to a TabPage
control and fit to its size?
Upvotes: 2
Views: 10970
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
Reputation: 116108
PictureBox pb = new PictureBox();
pb.Dock = DockStyle.Fill;
tabPage.Controls.Add(pb);
Upvotes: 6