I am developing a windows form application in C#. This application shows some text on the Form when a special kind of external event occurs (For example suppose that I want to write "Mouse is on upper line" on form when in the mouse's position y=0). I need to bring the Form to top of every other window when the event occurs.
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.
Press "Ctrl" and drag your mouse to duplicate a existing form class file. Then exlude the existing form class file from the project.
To create a ProgressBar control at design-time, you simply drag a ProgressBar control from the Toolbox and drop onto a Form in Visual Studio. After you the drag and drop, a ProgressBar is created on the Form; for example the ProgressBar1 is added to the form and looks as in Figure 1.
Use this in you form class:
public void BringToTop()
{
//Checks if the method is called from UI thread or not
if (this.InvokeRequired)
{
this.Invoke(new Action(BringToTop));
}
else
{
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
//Keeps the current topmost status of form
bool top = TopMost;
//Brings the form to top
TopMost = true;
//Set form's topmost status back to whatever it was
TopMost = top;
}
}
According to this source you can simply do form.Activate();
P.S. You may find this information useful too.
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