Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# form on top of all windows

Tags:

c#

forms

I am launching a C# made form from VBA code inside an Excel workbook.

I'd like this form to appear on top of all other windows/Applications including the Excel workbook.

I'd tried combinations of

        Form1 f = new Form1();
        f.Focus();
        f.ShowDialog();
        f.Activate();
        f.Show();

But none of them seems to work. Any hints?

Many thanks

JB

like image 710
Juan Chô Avatar asked Dec 15 '22 11:12

Juan Chô


2 Answers

Set the TopMost property to true.

f.TopMost = true;
like image 80
John Koerner Avatar answered Dec 27 '22 13:12

John Koerner


I found a tricky way of doing it: I maximized and then turned back to normal:

        Form1 f = new Form1();
        f.WindowState = FormWindowState.Maximized;
        f.Focus();
        f.Show();
        f.WindowState = FormWindowState.Normal;
        Application.Run(f);
like image 33
Juan Chô Avatar answered Dec 27 '22 15:12

Juan Chô