Creating windows forms open new form - c#

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 where 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();
}

Related

move parent form when child form moves in c# winforms

ok , i searched but didnt find what i want so far...
i have a main form and another form named RadEditTemplate.. i ShowDialog() the edit form like this :
new RadEditTemplate().ShowDialog();
i made the RadEditTemplate form the same size as the main form and made it center.
i want to lock these forms together so when i move the editform the main form move with it as well.
i have seen this in Winscp app before.
how can i do this ?
In MainForm:
Form RadEditTemplate = new Form();
RadEditTemplate.Move+=On_Move;
RadEditTemplate.ShowDialog();
void On_Move(object sender, EventArgs e)
{
this.Location = new Point(((Form)sender).Location.X, ((Form)sender).Location.Y);
}

visual basic 12 windows form

I am new to using windows form C# in visual basic 12 . In a ASP.NET form, you can right click on a linkbutton or imagelink, click preferences, and enter in a form under postbackurl to go to the that form after clicking the link/image. How is this done using a linklabel in a windows form? I cannot seem to figure this out.
This is the code you're looking for (by example).
Of course form2 is a new separate form. ;)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 newForm = new Form2();
newForm.Show();
}
}
Why would you want to do that?
Windows Forms work on a very different way and level opposed to Web based forms.
In web based forms you have a kind of navigation where you go from one to another page. The original page kind of seizes to exist.
In windows forms you will always have a master window (your application) which call's other windows to open.
The closest thing you can achieve is a linkbutton that opens a new Window or you have to use webpages inside the browsercontrol inside your Windows Form window.

C# - How to close current window and get new window

I'm implementing a window form in C#. I want to close current window and open a new window. (Just like File->New function in applications)
This is my code
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Image_Editor IE = new Image_Editor(); //Image_Editor is the name of window
IE.Show();
this.Close();
}
Images of what I want to achieve:
(source: infosight.com)
I want to implement the "new" function as shown in the above link. When executing given code, new window just appeared and both windows close at the same time.
What should I do to solve this?
if you mean that you want to close this windows and open a windows like your current windows use this
Myform frm; //thats name of the class of your form like Form1
frm = new Myform();
frm.Show(); // show the secend one
this.Close(); // and close the first one

Properties Window in C#

I'm currently trying to create a Properties Window which is opened after a Button on the Outlook Toolbar is pressed, i now have:
1) the Button on the Toolbar (currently if pressed nothing occurs)
2) i know how to create the method which would hold the action after the Button is Pressed
-but, I am a beginner and i don't know how to create a window which would open after the button is pressed, the Window should be fairly big, and for now have nothing but a checkbox(which i later would like to apply some method to.
if you ever created a window which opens after a button is pressed, i would be really pleased to get your help.
All help is appreciated, thank you
Here's the recommended way of opening a dialog window when the user clicks a button:
Add a new form to your project (e.g. MyForm) and then you can use the following code in your button's click event handler:
private void OnMyButtonClicked(object sender, EventArgs e)
{
MyForm myForm = new MyForm();
if (myForm.ShowDialog() == DialogResult.OK)
{
// The code that should be executed when the dialog was closed
// with an OK dialog result
}
}
In case you do not want the new window to be modal (i.e. you want to allow the user use other parts of the application while the window is opened), the code gets even more simple:
private void OnMyButtonClicked(object sender, EventArgs e)
{
MyForm myForm = new MyForm();
myForm.Show();
}
You can also create your form on the fly without adding one to your project, which is a bit more complicated, but advanced developers prefer this approach instead of messing with the designer ;)
private void OnMyButtonClicked(object sender, EventArgs e)
{
Form myForm = new Form();
myForm.Text = "My Form Title";
// Add a checkbox
CheckBox checkBox = new CheckBox();
checkBox.Text = "Check me";
checkBox.Location = new Point(10, 10);
myForm.Controls.Add(checkBox);
// Show the form
myForm.Show();
}
Here is a small tutorial for you to follow..
http://msdn.microsoft.com/en-us/library/ws1btzy8%28v=vs.90%29.aspx
EDIT: I would also recommend you remember the msdn website because it will prove invaluable for other programming issues you come across..
you have to add a new form to your project. Then you call the constructor where you want to pop up the window.
like this
Form2 form2 = new Form2();
form2.showDialog();
Edit:
where form2 is not the "main" Form of you program.
This'll set your main window to the background as long as the newly popped up window is closed.

How to open a new independent form?

I'll start with a code:
private void button_newform_Click(object sender, EventArgs e)
Form newF = new Form();
newF.show();
I have a form with a button who can open a new form.
the problem is, the new form have parent.
for example, if I'll click on newform button, it will create a new form.
but when I close this form, the new form will be closed too.
how to create an independent form, from an existing form?
The reason this is happening is because in the project->application properties, the shutdown mode is set to When startup Form closes. Change that to When Last form closes.

Categories