Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring dialogbox on top all open form

Tags:

c#

I have three forms Main, Sales and Login.

In Main form I have a timer, example after 5 minutes Login form will be fire up.

I can Open a Sales form the Main form whitout closing the Main form, so Login form will be fire up.

The problem is the Login form does not focus on top of the Sales form, so that the user must login to use the sales form.

Some code on Main form :

public void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
    LoginDialog loginForm = new LoginDialog();
                loginForm.TopLevel = true;
                loginForm.ShowDialog();
timer.Start()
}

 private void pbSales_Click(object sender, EventArgs e)
        {
            Sales salesForm = new Sales();
            salesForm .ShowDialog(this);
        }
like image 217
Alvin Avatar asked Jul 13 '12 10:07

Alvin


People also ask

How do you make a form always on top?

You can bring a Form on top of application by simply setting the Form. topmost form property to true will force the form to the top layer of the screen, while leaving the user able to enter data in the forms below. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop.

How to show Message box on top in c#?

Your best bet would be to create a form that acts like a MessageBox - i.e. set its TopMost property to true and call it with the . ShowDialog() method. MessageBox. Show(new Form() { TopMost = true }, "I'm on top!");

What is ShowDialog C#?

ShowDialog() Shows the form as a modal dialog box. public: System::Windows::Forms::DialogResult ShowDialog(); C# Copy. public System.Windows.Forms.


2 Answers

EDIT

try combination of both that will might work for you..

private void frmMain_Shown(object sender, EventArgs e)
{
// Make this form the active form and make it TopMost
this.ShowInTaskbar = false;
this.TopMost = true;
this.Focus();
this.BringToFront();
this.TopMost = false;
}

try this out

yourForm.TopMost = true;

or

Control.BringToFront Method

yourform.BringToFront()
like image 188
Pranay Rana Avatar answered Sep 19 '22 01:09

Pranay Rana


I think the issue is you are calling ShowDialog from the MainForm and you have the Sales Form open also.

The parent for the Dialog happens to be the MainForm, so maybe you can try using

loginForm.ShowDialog(saleform1);

salesform1 is the instance name of the Sales Form you opened from the Main form.

like image 22
V4Vendetta Avatar answered Sep 20 '22 01:09

V4Vendetta