如何以编程方式将PictureBox
控件添加到TabPage
控件并适合其大小?
PictureBox pb = new PictureBox();
pb.Dock = DockStyle.Fill;
tabPage.Controls.Add(pb);
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.