c# - 从另一个表单更改表单的 TopMost
问题描述
我正在尝试从“设置”表单更改我的主表单的最顶部,但它不起作用。这是代码:
private void button1_Click(object sender, EventArgs e)
{
if (this.button1.Text == "Top Most: ON")
{
this.button1.Text = "Top Most: OFF";
var main = new Main();
main.TopMost = false;
}
else if (this.button1.Text == "Top Most: OFF")
{
this.button1.Text = "Top Most: ON";
var main = new Main();
main.TopMost = true;
}
}
解决方案
在设置表单中:
private MainForm _mf;
public SettingsForm(MainForm mf){
InitializeComponent();
_mf = mf;
}
private void button1_Click(object sender, EventArgs e)
{
_mf.TopMost = !_mf.TopMost;
this.button1.Text == "Top Most: " + _mf.TopMost ? "ON" : "OFF;
}
在显示设置的主窗体中:
new SettingsForm(this).Show...
推荐阅读
- c++ - 如何在有条件的情况下计算 3d 网格中从一个点到另一个点的所有路径
- scala - 类似于函数式Scala中的for循环
- java - 如何将我的代码分解为子例程 - Java
- r - 如何循环日期?
- javascript - 使用 JavaScript,我将如何编写“如果下一个兄弟姐妹具有特定的类名 xxx,则执行此操作,否则执行此操作”?
- c++ - C++ - 为什么我的程序在再次调用函数后关闭?
- javascript - 在张量流中为张量层解包位时性能缓慢
- node.js - sqllite3安装在节点和macos上给出错误
- filter - BigCommerce Stencil 如何嵌套 {{filter}} Handlebars Helper?
- asp.net-mvc - 使用字符串调用实体框架中的表