I'm trying to change the topmost of my Main form from the Settings form and it doesnt work. Here is the code:
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;
}
}
In the settings form:
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;
}
And in your main form that shows the settings:
new SettingsForm(this).Show...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.