When you create a new Windows Forms application, what's the easiest way from dropping a button on the page, creating a click event which will open a new form.
My method requires clicking a button which will open up 9 new forms, all together, but I want to be able to position them wher开发者_运维技巧e I want, I know the code for this, I just can't seem to open up multiple new forms at the same time?
Button -> Click -> Open 9 new forms which must be open at the same time.
To open a new form
MyForm myForm = new MyForm()
myForm.Show();
Where MyForm
is a class that inherits from Form
(i.e. your designed form)
How you would do this would depend on whether the forms are all the same or not but
For i as integer = 0 to 8
dim frm as new Form1
frm.Show
Next
Using the static method ie: form1.show is not generally a good idea.
Cheers
Solution in C# using System.Windows.Forms
private void Button_Click(object sender, EventArgs e)
{
Form myForm = new Form();
myForm.Show();
}
To open more than 1 form, a loop with each form would be required.
foreach (Form form in formArray)
{
form.Show();
}
精彩评论