你好,我正在尝试让TopMost切换开关,这里是代码: private void bunifuiOSSwitch1_OnValueChange(object sender,EventArgs e)
private void bunifuiOSSwitch1_OnValueChange(object sender, EventArgs e)
{
Main main = new Main();
if(bunifuiOSSwitch1.Value == true)
{
main.TopMost = true;
}
else
{
main.TopMost = false;
}
}起初,它在切换到true时起作用,在切换到false时起作用,但当我试图重新打开它时,它不起作用,之后我试图再次更改代码,但这也不起作用……现在它甚至不能TopMost了。
发布于 2020-06-28 07:27:01
您需要做的是将一个对Main的引用传递到您的Settings窗体中。一种方法是在调用Show()或ShowDialog()时
// ... in Form Main ...
private void button1_Click(object sender, EventArgs e)
{
Settings settings = new Settings();
settings.Show(this); // pass in this instance of Main as the "owner" of settings
}然后,在设置中,您可以将.Owner属性转换回Main类型并对其执行操作:
// ... in Settings Form ...
private void bunifuiOSSwitch1_OnValueChange(object sender, EventArgs e)
{
if (this.Owner!=null && this.Owner is Main)
{
Main main = (Main)this.Owner;
main.TopMost = (bunifuiOSSwitch1.Value == true);
}
}https://stackoverflow.com/questions/62611092
复制相似问题