C# - How to make a window stay on top and become transparent
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;
}
}

Tags: always on top, C#, code, Software, source, stay on top, transparent
September 15th, 2008 at 5:47 pm
Thanks a lot for the tips. I didn’t ever realise that this was so simple :). Thanks again.