Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2006

Tip: Looking for answers? Try searching our database.

Activate Main Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Byrnes - 14 Jan 2006 16:59 GMT
I have a small windows form application. I have a main form and a second
form that I open from the main form menu.

The second form opens in a fully maximized windows. I cannot figure out how
to activate or show the main form from the second forms menu (ie, what code
to put in the menu event). I can actiate the second form easily becasue
there is a variable used to create it:

SecondForm secondForm=new SecondForm();
secondForm.Show();

But the way the main (startup) form is initialized, there is no variable.

Any help is appreciated.

Bill Byrnes
Tim Wilson - 14 Jan 2006 17:29 GMT
One way to do this is to create a constructor overload in SecondForm that
accepts a Form...

public class SecondForm : Form
{
 private Form mainForm = null;

 public SecondForm (Form mainForm)
 {
   this.mainForm = mainForm;
 }

 // And then in the event handler for the menu item...
 // if (this.mainForm != null)
 // { this.mainForm.BringToFront(); }
}

In the main Form when creating the SecondForm instance use code like this...

SecondForm secondForm = new SecondForm(this);
secondForm.Show();

Signature

Tim Wilson
.NET Compact Framework MVP

> I have a small windows form application. I have a main form and a second
> form that I open from the main form menu.
[quoted text clipped - 12 lines]
>
> Bill Byrnes

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.