c# - Application.SetCompatibleTextRenderingDefault(false); 时出现运行时错误 已设置
问题描述
尝试从Console
应用程序转换为应用Winform
程序。以下Winform
代码编译良好,但在运行时出现以下错误。我在网上经历了类似错误的各种解决方案,但仍然有点困惑。也许,这里有人可以为我的以下特定代码提供帮助:
注意:这可能与这篇文章的问题无关。但以防万一:我micaut 1.0 Type Library
在我的VS2017
项目中引用了以下代码所需的内容。
错误[在 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();
}
解决方案
正如错误试图告诉您的那样,您只能在创建第一个表单之前调用该函数。
将其移至Main()
(如果它不存在)。
推荐阅读
- sharepoint-online - Sharepoint Online REST 奇怪错误(400)-“值不能为空。参数名称:键”
- python - 给定两列相同的熊猫,在行中找到相似的元素以创建新列
- ios - 英语字符串集与支持 UIStoryboard 的本地化相结合
- python - 根据 Pandas 行中的列名创建变量
- vuejs2 - 数组更改不会重新渲染模板
- excel - 从命名范围偏移创建范围
- arrays - 如何让 Arrayformula 在自动填充时查找 Arrayformula?
- if-statement - 如何根据条件选择应用哪个装饰器?
- c# - C#如何用out分隔符分隔字符串?
- mosquitto - Telegraf 启动问题