2012-11-11 23 views
0

在button1_Click上,我試圖增加圖像的大小10或放大它。但是,情況正在發生變化,圖片框的大小正在增加,圖片上沒有任何事情發生。如何繼續圖像縮放。請給我建議最簡單的方法。試圖放大在winform c中的圖像#

public partial class Form1 : Form 
{ 
public Form1() 
{ 
    InitializeComponent(); 
} 
private void pictureBox1_Click(object sender, EventArgs e) 
{ 
    // Construct an image object from a file in the local directory. 
    // ... This file must exist in the solution. 
    Image image = Image.FromFile("Picture1.png"); 
    // Set the PictureBox image property to this image. 
    // ... Then, adjust its height and width properties. 
    pictureBox1.Image = image; 
    pictureBox1.Height = image.Height; 
    pictureBox1.Width = image.Width; 
    } 
} 
    private void Form1_Load(object sender, EventArgs e) 
    { 

    } 
    private void button1_Click(object sender, EventArgs e) 
    { 
     pictureBox1.Width += 10; 
     pictureBox1.Height +=10; 

    } 

回答

0

與您試圖實現的簡單方法是使用PictureBox的SizeMode屬性;將其設置爲StretchImage。

PictureBox.SizeMode Property - MSDN

然而,一旦你與GDI +(甚至不安全的環境中)更舒服,你應該看看這樣做編程方式爲自己更大的靈活性。