Solved

Create a new form

Posted on 2006-07-18
4
248 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Handling arrays 14 33
Using MS Code on my Mac 6 45
Expando 4 33
Calling stored proc in EDMX 11 18
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now