I would like to know the difference between form.show()
and form.activate()
.
I have multiple forms that already opened and i would like to active my form that is behind another form which is the best way to call my desired form
form.show()
or form.activate()
?
The method Show()
displays the form to the user.
The method Activate()
brings the form to the front (it gives the form focus).
For example:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
this.Activate();
}
}
The above code will show form2 by calling form2.Show();
but form1 will be in front of form2 (in focus) because of the this.Activate();
call.
See MSDN documentation:
From the documentation
Form.Activate Method ()
Activating a form brings it to the front if this is the active application, or it flashes the window caption if this is not the active application. The form must be visible for this method to have any effect. To determine the active form in an application, use the ActiveForm property or the ActiveMdiChild property if your forms are in a Multiple-document interface (MDI) application.
Form.Show Method
Showing the control is equivalent to setting the Visible property to true. After the Show method is called, the Visible property returns a value of true until the Hide method is called.
Answer
I have multiple forms that already opened and i would like to active my form that is behind another form which is the best way to call my desired form form.show() or form.activate()?
If your form is already open Activate
it probably the one you want
Tip : If you ever wonder what a .net method does, just go and type it into google, usually the help is the first thing that shows up, plus a myriad of other questions and answers
form.activate()
activates the form, which means if you have input elements (such as text boxes), it will focus to that particular form regardless of any other form out there. Eg. If you have shown form 1,2 and 3. And if you activate form 2, the form 2 will get focused to the user.
If you use form.show()
it will just display/show the form to the user. Thus the activate()
is gets the highest priority in terms of user engagement.
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