运行 time Error when Application.SetCompatibleTextRenderingDefault(false);已设置

Run time Error when Application.SetCompatibleTextRenderingDefault(false); is set

正在尝试从 Console 应用程序转换为 Winform 应用程序。以下 Winform 代码编译正常,但在运行时出现以下错误。网上看了各种类似错误的解决办法,还是有点迷糊。也许,这里有人可以为我提供以下特定代码的帮助:

注意:这可能与 post 的问题无关。但以防万一:我在我的 VS2017 项目中引用了下面代码所需的 micaut 1.0 Type Library

错误 [在 Winform 上]:

SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.

来自控制台应用程序的代码:

using System;
using System.Windows.Forms;
using micautLib;

namespace MathInputPanel
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MathInputControl ctrl = new MathInputControlClass();
            ctrl.EnableExtendedButtons(true);
            ctrl.Show();
            ctrl.Close += () => Application.ExitThread();
            Application.Run();
        }
    }
}

尝试将上述代码转换为 Winform 应用程序[给出错误]:

using System;
using System.Windows.Forms;
using micautLib;

private void button1_Click(object sender, EventArgs e)
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false); //error occurs here

    MathInputControl ctrl = new MathInputControl();

    ctrl.EnableExtendedButtons(true);
    ctrl.Show();
    ctrl.Close += () => Application.ExitThread();
    Application.Run();
}

正如错误试图告诉您的那样,您只能在创建第一个表单之前调用该函数。

将它移到 Main()(如果它还没有)。