C#picturebox中的图像怎么能随着窗体的大小而改变

来源:百度知道 编辑:UC知道 时间:2024/06/24 11:35:38
我在picturebox中利用graphics画了一张图,哪位朋友知道怎么做才能使picturebox中的图与窗体大小的改变同步!
我是菜鸟,能说的具体点吗?谢谢了

1、思路
设置PictureBox的SizeChanged事件,比如PictureBox名为“pictureBox1”,高度和宽度都是200,上面有一个名为“button1”的按钮和一个名为“label1”的标签,现在要设置在pictureBox1的大小发生变化时按钮和标签按照它大小变化的比例同时变化即可完成。
2、代码如下:
private void pictureBox1_SizeChanged(object sender,EventArgs e)
{
this.button1.Size=new Size(this.pictureBox.Width/200*this.button1.width,
this.pictureBox.Width/200*this.button1.Height);
this.label1.Size=new Size(this.pictureBox.Width/200*this.label1.width,
this.pictureBox.Width/200*this.label1.Height);
}

首先设置PictureBox的SizeMode属性为StretchImage或者Zoom,然后在Form的sizeChange事件中,改变PictureBox的大小 就可以实现你的要求

this.pucturebox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));

你把这行代码写到你的构造函数里