Whilst looking for information on how to make a window stay on top using C#, I spotted some odd solutions on a number of other web sites. After looking through the Form properties in Visual Studio C# 2008 myself it turns out that it is really easy to make a window stay on top. I added a check box to by application and when it is ticked the window stays on top.
private void stayOnTopCheckBox_CheckedChanged(object sender, EventArgs e) { if (stayOnTopCheckBox.Checked) { this.TopMost = true; } else { this.TopMost = false; } }
Along the same theme of ‘very cheap and quick tricks that you add to your C# program’ I added another box to make the window transparent. Below is the code and the result of ticking this box.
private void transparentCheckBox_CheckedChanged(object sender, EventArgs e) { if (this.transparentCheckBox.Checked) { this.Opacity = 0.5; } else { this.Opacity = 1; } }
Thanks a lot for the tips. I didn’t ever realise that this was so simple :). Thanks again.
Thanks, Just what I needed….
FYI, for noobs (
add your own check box and double click on it and then add
ie
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
this.TopMost = true;
else
this.TopMost = false;
}
Thanks for this, it was just what I needed. Knowing C# it was just finding the right property.