【发布时间】:2019-05-17 02:18:13
【问题描述】:
尝试从Console 应用转换为Winform 应用。以下Winform 代码编译良好,但在运行时出现以下错误。我在网上经历了类似错误的各种解决方案,但仍然有点困惑。也许,这里有人可以为我的以下具体代码提供帮助:
注意:这可能与本文的问题无关。但以防万一:我在下面的代码所需的VS2017 项目中引用了micaut 1.0 Type Library。
错误 [在 Winform 上]:
必须在应用程序中创建第一个 IWin32Window 对象之前调用 SetCompatibleTextRenderingDefault。
来自控制台应用的代码:
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();
}
【问题讨论】:
标签: c# office-interop