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);
}
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.
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!");
ShowDialog() Shows the form as a modal dialog box. public: System::Windows::Forms::DialogResult ShowDialog(); C# Copy. public System.Windows.Forms.
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()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With