none
Toggable Topmost button in C# RRS feed

  • Question

  • How could I make a toggleable button to make the UI top most applications in c#? I am trying to make an application and want to have the option to make it topmost applications.
    • Moved by CoolDadTx Thursday, August 9, 2018 1:48 PM Winforms related
    Wednesday, August 8, 2018 6:15 PM

All replies

  • Hello,

     The following assistance only applies to Windows Forms project builds.

     

     1. Drag a Button object onto your Form.

     2. Make visual changes that your prefer, color, text font, etc.

     3. Change Button.Text to something relative to its function.

     4. Subscribe your Button to Event Mouse_Click handler.

     5. Use the following code, inside the Button event handler, brackets;

    private void button1_MouseClick( object sender, MouseEventArgs e )
    {

    this.TopMost ^= true;

    }

     6. Compile and execute the project to see if works as expected.

     

     The code that I have provided, should on every Mouse Click event,

    toggle the state of the Forms property TopMost.  However, there

    are some objects that will override TopMost such as Dialogs.

    Even when Dialog has lost Focus, can remain TopMost, until closed.

     Hope this helps :)

    Thursday, August 9, 2018 2:09 AM
  • can you help me with this but with flatButton2? I broke my project..
    Thursday, November 7, 2019 1:27 AM