PictureBox.BackgroundImageLayout更改失败

问题描述 投票:0回答:2

我正在使用Visual Studio 2010并在c#中编写一个简单的项目。我有一个图片框和两个按钮。按下一个按钮时,图片框中的图像会发生变化,但我无法更改背景图像布局属性。按钮回调类似于:

pictureBox1.BackgroundImage = Image.FromFile("test.jpg");  
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;

图像已更改,但未在图片框上拉伸。实际上,只显示了适合图片框的部分图像。

有什么建议?

UPDATE

这是我的错。按钮回调中的调用实际上是:

pictureBox1.Image = Image.FromFile("test.jpg");
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;

而不是上层陈述。

c# visual-studio-2010 layout picturebox
2个回答
0
投票

如果要在控件的客户端矩形中放大并调整图像,请将BackgroundImageLayout设置为ImageLayout.Zoom

pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;

您也可以尝试SizeMode财产

pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

0
投票
private void button1_Click(object sender, EventArgs e)
{
    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    pictureBox1.Image = Image.FromFile("D:/elefent.jpg");      
}

我使用时,pictureBox布局发生了变化:

pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
© www.soinside.com 2019 - 2024. All rights reserved.