Juan Chô
Juan Chô

Reputation: 572

C# form on top of all windows

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

Upvotes: 5

Views: 8867

Answers (2)

Juan Chô
Juan Chô

Reputation: 572

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

Upvotes: 3

John Koerner
John Koerner

Reputation: 38077

Set the TopMost property to true.

f.TopMost = true;

Upvotes: 11

Related Questions