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.

Visual C# buttons

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;
    }
}

Visual C# transparent buttons

3 Comments on “C# – How to make a window stay on top and become transparent”

  1. 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;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Do NOT fill this !