2011-05-30 109 views
2

我最近採取了我的第一步到GDI +,並試圖從位圖中繪製圖像。 我的代碼是這樣的:幫助GDI +圖像繪圖

using System.Drawing; 
using System.Drawing.Drawing2D; 

namespace Windowstuffs 
{ 
    class AnimEngine : Form 
    { 
     public Graphics X; 
     public Bitmap Y = new Bitmap(/* File Path */); 

     void draw(object sender, PaintEventArgs e) 
     { 
      Bitmap Y = new Bitmap(/* File Path */); 
      e.Graphics.DrawImage(Y, 0, 0); 
      return; 
     } 

     public static void Main() 
     { 

      AnimEngine f1 = new AnimEngine(); 
      Application.Run(f1); 
      f1.Paint += new PaintEventHandler(f1.draw); 
      f1.Refresh(); 
      return; 
     } 

    } 
} 

它編譯就好了,但是,它不畫任何東西。其他的功能都是完全正常的,在搜索完MSDN和各種教程之後,我仍然無法找到我做錯了什麼。

謝謝你的幫助。

回答

2
public static void Main() 
{ 

    AnimEngine f1 = new AnimEngine(); 
    f1.Paint += new PaintEventHandler(f1.draw); 
    Application.Run(f1); 
    f1.Refresh(); 
    return; 
} 

只要把上面的Application.Run(F1)行:)

+0

由於事件訂閱行,但後來我怎麼養Paint事件後,我先裝的形式? – 2011-05-30 10:47:58

+0

您可以調用該控件的Invalidate方法。 [鏈接] http://msdn.microsoft.com/en-us/library/598t492a.aspx – Eranga 2011-05-30 11:24:46

+0

好的,謝謝。 – 2011-05-30 11:30:20