Reputation: 1
I have a thing where you click "options" and it opens the Form "options" I want it so when you enable "TopMost" it happens on the main Form rather than the settings,
{
if (bunifuiOSSwitch1.Value == true)
{
this.TopMost = true;
}
else
{
this.TopMost = false;
}
}
Thats the code I have in the button
Upvotes: 0
Views: 39
Reputation: 74690
this.TopMost
sets the current form that is executing the code (the settings form) to be TopMost, when you probably want some other form to be the topmost.. This means that your settings form either needs some access to whatever form you want to be topmost:
public class SettingsForm{
private Form _mainForm;
public SettingsForm(Form mainForm){ //settings form constructor takes mainform as a parameter
_mainForm = mainForm;
}
void ApplySettingsButtonClick(...)
{
_mainForm.TopMost = bunifuiOSSwitch1.Value;
}
}
And then open your settings form you pass the mainform in:
void OpenSettingsButon_Click(...){
new SettingsForm(this).ShowDialog();
}
Or you have some shared thing that both forms can access, like the Settings mechanism, where your settings form will set Properties.Default.Settings.MainfFOrmIsTopMost = true
and then your main from can react to the change (perhaps by an event handler) and set the value of topmost based on the Settings setting
Careful though; in either case, making the main form topmost will make it sit on top of the settings window.. and if the settings window is a dialog it could get stuck behind unless it is also TopMost.
Using TopMost is often something that actually should be avoided if you can..
Upvotes: 1