How to set the standard visibility of the main Winform

I run my program step by step, but still I can not find where form.visible installed.

Here is the code "Form1.cs":

 public Form1() { InitializeComponent(); this.Hide(); } 

I added this.Hide(); but it didn’t work at all.

and I even modified "Program.cs":

 Application.Run(new Form1()); 

in

 Form1 form1=new Form1(); form1.Visible = false; Application.Run(form1); 

But the main form was still showing, even adding form1.Enable=false; won't stop the form. I also tried adding this.Hide(); in Form1_Load() , it worked, but the main form appeared and flashed before it was finally hidden.

Now I'm completely confused. So how can I load the main form without showing it? And keep it hidden until I call this.Show(); ?

0
source share
6 answers

Why not override the SetVisibleCore method:

 bool showForm = false; protected override void SetVisibleCore(bool value) { base.SetVisibleCore(showForm); } 

This will hide the form until it opens. Using a large number of methods, you see a short flash of the form before it. An available or similar property is set to "hidden."

Obviously, you will need another way to flip 'showForm' to true if you want to display it again, i.e. NotifyIcon event.

+2
source

you cannot set the visible form to false before loading, try this code:

 //In Main Function Form1 form1 = new Form1(); form1.WindowState = FormWindowState.Minimized; form1.ShowInTaskbar = false; Application.Run(new Form1()); //In Form Shown private void Form1_Shown(object sender, EventArgs e) { this.Visible = false; } 
+2
source

The documentation for Application.Run (Form) clearly states that it will make the view visible. If you need to hide it, you should not submit this form to Application.Run. Depending on your needs, you can use Application.Run () (without arguments) or Application.Run (context) (create a custom ApplicationContext ).

Edit: I just want to add that in order not to show the form, you should not show the form . I don’t understand how many users here consider it a good idea to show the form and then hide it very quickly or make code that shows a form that does not display the form. You must not do wrong, and then fix it after the fact, you must do right in the first place.

+2
source

You might be looking for the Opacity property. You can set Opacity to 0.0 from the IDE. It can take values ​​between 0.0 and 1.0 .

+1
source

You can try something like this:

  [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var form = new Form1(); form.DoBeforeShow(); Application.Run(form); } 
0
source

First, you can download the form that you constantly want to show to the user. In the constructor, we only call the form, which should be hidden. Subsequently, you can close or hide it.

0
source

Source: https://habr.com/ru/post/1433121/


All Articles