我最近迈出了进入 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 和各种教程进行搜索后,我仍然找不到我做错了什么。
感谢您的帮助。
最佳答案
public static void Main()
{
AnimEngine f1 = new AnimEngine();
f1.Paint += new PaintEventHandler(f1.draw);
Application.Run(f1);
f1.Refresh();
return;
}
只需将事件订阅行放在 Application.Run(f1) 行之上:)
关于c# - 帮助 GDI+ 图像绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6174536/