c# - 无法将类型“System.Windows.Forms.Form”隐式转换为“bool”
问题描述
我将 DiscordRPC 放入我的应用程序中。我确保窗口处于活动状态,因此它可以轻松更改并实际更改状态。问题是在使用 ActiveForm 时,它不起作用,因为它无法将其转换为“布尔”。这是我的代码。
private void active()
{
Form currentForm = Form.ActiveForm;
if(Form.ActiveForm)
{
ptr2tools.Presence = new RichPresence()
{
State = "Using pwf2tex",
Assets = new Assets()
{
LargeImageKey = "pwf2tex",
LargeImageText = "pwf2tex"
}
};
ptr2tools.DiscordClient.SetPresence(ptr2tools.Presence);
}
}
解决方案
Form.ActiveForm 保留当前活动的表单,如果没有活动的表单,则为 null。
var currentForm = Form.ActiveForm;
if(currentForm != null)
{
//logic
}
推荐阅读
- java - Files.readAllBytes() 是否在读取文件后关闭输入流?
- angular - 无法绑定到“routerlink”,因为在执行教程时它不是“a”的已知属性
- c# - 恢复 WCF REST API 的帐户功能
- python - Django 正在向我发送一封关于“无效 HTTP_HOST 标头”的电子邮件
- matlab - mex编译代码语句中如何使用变量?
- laravel - Laravel RESTAPI,显示来自服务器端的调试
- python - 以前未见过的 Web 元素参考
- javascript - 通过 Javascript 更改范围滑块背景
- python - 为什么 event.type 函数返回名称错误?
- ios - Swift 编译错误 - 无法构建 Objective-C 模块“RxAlamofire”