2013-11-03 87 views
0

我有一點點prolem繪製位圖到屏幕上一個位圖,我試圖用對MSDN庫中的顯示方式,這部分工作,但他們並沒有真正給出一個很好的例子,在那裏,只是specyfying你需要PaintEventHandler。繪圖使用的DrawImage

所以這是我的代碼:

public class UI { 
    public static void DrawTexture(string path, int x, int y, PaintEventArgs e) { 
     Bitmap BM = new Bitmap(path); 
     e.Graphics.DrawImage(BM, x, y); 
    } 
} 

現在,這個應該工作,但在調用函數時,問題就來了:

UI.DrawTexture("somepic.png", 1,1, /* What to put in here? */); 

我在表單中使用它也嘗試:

private void Form1_Load(object sender, EventArgs e, PaintEventArgs p) { 
    UI.DrawTexture("somepic.png", 1,1, p); 
} 

這給我一個錯誤在調試時:「不超載的Form1_Load的匹配委託System.EventHand LER「。

我在哪裏錯了?

回答

0

沒有重載Form1_Load的匹配委託System.EventHandler「

的Form_Load的委託函數是這樣的(它不會有一個名爲參數 「PaintEventArgs的」。

private void Form1_Load(object sender, EventArgs e) { 
    //Your codes here…… 
} 

所以現在請輸入Form_Paint事件:

private void Form1_Paint(object sender, PaintEventArgs e) 
     { 
UI.DrawTexture("somepic.png", 1,1, e); 
     } 
+0

非常感謝。 – user2948815

相關問題