[英]How to programmatically add PictureBox control to the tab page control
如何以编程方式将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
但是,如果标签页的唯一目的是显示图像,则最好使用标签页本身的“ BackgroundImage”并使用其
BackgroundImageLayout
来保持图像大小,与添加PictureBox
相比,这节省了一些麻烦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.