?
Solved

Create a new form

Posted on 2006-07-18
4
Medium Priority
?
287 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 900 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 300 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 300 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

771 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