帮助进行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);
            return;
        }

       public static void Main()
        {

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

    }
}
它可以正常编译,但是它不会绘制任何内容。其他所有功能都完全正常,并且在搜索了MSDN和各种教程之后,我仍然找不到我做错了什么。 谢谢您的帮助。     

解决方法

        
public static void Main()
{

    AnimEngine f1 = new AnimEngine();
    f1.Paint += new PaintEventHandler(f1.draw);
    Application.Run(f1);
    f1.Refresh();
    return;
}
只需将事件订阅行放在Application.Run(f1)行上方即可:)