Technology, life, programming, travel and money.

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


Reader Feedback

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

  1. desert says:

    Thanks a lot for the tips. I didn’t ever realise that this was so simple :). Thanks again.

  2. Tom says:

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

  3. Alec says:

    Thanks for this, it was just what I needed. Knowing C# it was just finding the right property.

Leave a Reply

Do NOT fill this !