c# - 帮助 GDI+ 图像绘制

标签 c# winforms gdi+ paint

我最近迈出了进入 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/

相关文章:

c# - PrintDocument 总是有边距

c# - 如何在 ASP.NET 中使用 C# 从数据库中检索二进制图像

c# - FabricNotReadableException 是什么意思?我们应该如何应对?

c# - IOC 容器实际上为我做了什么?

c# - 如何知道TextEdit中当前的可见性偏移量?

c# - 执行 "if"语句的更快方法

c# - 如何为用户显示和隐藏 "Please wait"消息

c# - 如何使用 C# Complex 将矩形形式转换为极坐标形式

.net - 在用户控件中绘制简单的线条

winapi - 使用 GDI+ 的 Windows 初始屏幕