Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First: add the controls to <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx" rel="nofollow"><code>newWindow.Controls</code></a>.</p> <p>Second: Do it before <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.run.aspx" rel="nofollow"><code>Application.Run</code></a> because it will show the form and then wait for it to close (note: the way the designer does it is to add them at the constructor of a class that derived from <a href="http://msdn.microsoft.com/en-us/library/System.Windows.Forms.Form.aspx" rel="nofollow">Form</a>).</p> <pre><code>private void CreateWindows() { newWindow = new Form(); //Application.Run(newWindow); //Not here //newWindow.Activate(); //Wont do anything newWindow.Size = new System.Drawing.Size(40, 40); Label label1 = new Label(); newWindow.Controls.Add(label1); //Good label1.Text = "HI"; label1.Visible = true; label1.Size = new System.Drawing.Size(24, 24); label1.Location = new System.Drawing.Point(24, 24); Application.Run(newWindow); //Here instead } </code></pre> <p>Third: if you have already used <code>Application.Run</code> in the current thread (say because you are doing this from a form), then there is no point to call it here. Use <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.show.aspx" rel="nofollow"><code>Show</code></a> or <a href="http://msdn.microsoft.com/en-us/library/System.Windows.Forms.Form.ShowDialog.aspx" rel="nofollow"><code>ShowDialog</code></a> instead.</p> <hr> <p>Also consider adding controls this way:</p> <pre><code>private void CreateWindows() { newWindow = new Form(); newWindow.Size = new System.Drawing.Size(40, 40); newWindow.Controls.Add ( new Label() { Text = "HI", Visible = true, Size = new System.Drawing.Size(24, 24), Location = new System.Drawing.Point(24, 24) } ); Application.Run(newWindow); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload