Solved

Create a new form

Posted on 2006-07-18
4
276 Views
Last Modified: 2010-04-16
I have a windows form, now I want  to minimize it and then make a new form. How could I do that, and by the way I want to get the position information. Thanks!
0
Comment
Question by:ed_dalian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 12

Accepted Solution

by:
topdog770 earned 300 total points
ID: 17132377
I create a new windows application and added a button2 with click event...

In this example, I create a second copy of the first form and change the window title.. so we can see the difference between the first and second window.. when hiding the first form, I also hide it on the taskbar so our users don't see multiple windows for this program after clicking on the button.

            private void button2_Click(object sender, System.EventArgs e)
            {
                  this.CenterToScreen();

                  Form1 dlg = new Form1();
                  dlg.Text = "Second Window";
                  dlg.Left = this.Left;
                  dlg.Top = this.Top;
                  dlg.Size = this.Size;
                  
                  // make the parent window hidden
                  this.Hide();
                  this.ShowInTaskbar = false;

                  if( dlg.ShowDialog() == DialogResult.OK )
                  {
                        Application.Exit();
                  }
                  else
                  {
                        this.Show();
                        this.ShowInTaskbar = true;
                  }
0
 
LVL 2

Assisted Solution

by:Linky
Linky earned 100 total points
ID: 17132383
So you want a new form to appear when you minimize the form you have now? Say you have Form1.cs and Form2.cs and you want to make a new one. In the code you do:

Form2 newForm = new Form2();

Then to make it appear you do:

newForm.Show();

To get the position information its just:

Form2.Location.X;
Form2.Location.Y;

To make a new form when you minimize a form you need to create an event handler function.
0
 
LVL 2

Assisted Solution

by:MyersA
MyersA earned 100 total points
ID: 17132977
You can use the SizeChanged event on the Form that'll be minimized.

Create a SizeChanged event handler:
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);

Then you can use this code in the eventhandler:

private void Form1_SizeChanged(object sender, EventArgs e)
{
        if (this.WindowState == FormWindowState.Minimized)
        {
                Form newForm = new Form();
                newForm.Show();
                MessageBox.Show(newForm.Location.X.ToString());  //newForm X coordinates
                MessageBox.Show(newForm.Location.Y.ToString());  //newForm Y coordinates
        }
}
0
 

Author Comment

by:ed_dalian
ID: 17135559
Thanks, all of you!
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question