2014-01-20 34 views
0

我有Visual Studio 2013,我正在編程在C#中。
我有這樣的代碼,但它不工作:(visual c#)不顯示我的圖像

public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     this.Text = "Bitmap loader"; 
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 
     this.MaximizeBox = false; 
     surface = new Bitmap(this.Size.Width, this.Size.Height); 
     pictureBox1.Image = surface; 

     device = Graphics.FromImage(surface); 
     image = Properties.Resources.dragon; 
     pictureBox1.Image = image; 
     device.DrawImage(Properties.Resources.dragon, 10, 10); 
     pictureBox1.Image = image; 
     this.Refresh(); 
    } 

我已經把this圖像到resurce。 當我點擊運行,它顯示一個空的窗口。

我怎樣才能實現這個屏幕顯示我的形象? (任何人都可以鏈接我的progect ???)

回答

0

我用這個代碼,它工作得很好。

確保設計編輯器中的圖片框具有大小。 嘗試使用圖片框上的小箭頭將其停靠在父容器上。還可以選擇設置縮放比例。

private void Form1_Load(object sender, EventArgs e) 
{ 
    this.Text = "Bitmap loader"; 
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 
    this.MaximizeBox = false; 

    this.pictureBox1.Image = Properties.Resources.dragon; 
} 
+0

這是行不通的 – Lorenzo

0

我已經提供了答案! 在Form1的() 的loadcompoents後,我必須把這個代碼

 this.Load += new EventHandler(this.Form1_Load) 

(沒有它無法加載Form1_Load的)