2011-05-30 80 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