Solved

c# windows app open another form on load

Posted on 2011-03-23
5
750 Views
Last Modified: 2012-05-11
Hi,

I am building a windows app in which I need to do this.

1) when the user clicks the icon to lauch the app I want it to load the form but also load another form "window" that displays certain information from the DB. Its like automatic reminders.

Question is how do i get another form to launch when openeing the main form.

Please help

Thanks,

R8VI
0
Comment
Question by:R8VI
  • 3
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35197477
You can simply have the Load event of the main form instantiate and show a secondary form:
// in load event of main form
SecondForm f = new SecondForm();
f.Show();

Open in new window

0
 
LVL 3

Expert Comment

by:MicMatic
ID: 35198854
If you want to make sure your new form to stay on top of the other form, you might want to use .ShowDialog()

The code is almost the same as mentioned above:

FormReminders frmReminders = new FormReminders();
frmReminders.ShowDialog();
0
 
LVL 3

Expert Comment

by:MicMatic
ID: 35198914
My bad, I intended to use preview...

An example of a basic class:

public partial class frmMainForm : Form {
  public frmIudexnet() {
    InitializeComponent();

    //You call your second form here (asuming you already created you form with the IDE)
    FormName frm = new FormName();
    frm.ShowDialog();
  }

Open in new window

0
 

Author Comment

by:R8VI
ID: 35202835
Hi,

Sorry I should have been a bit more specfic, I want the second form (reminders) to load and be displayed top left for example but first form to be displayed in the middle on the screen and focus on the first form

Thanks for the help so far

Thanks,

R8VI
0
 
LVL 3

Accepted Solution

by:
MicMatic earned 500 total points
ID: 35202967
In that case you should use this for your second form (after InitializeComponent()):

frmSecondForm.Show();

Open in new window


You can set the position using your Form-properties in your IDE: StartPosition: manual. After that you can set your location property to 0; 0

after calling the new form you can use:

this.TopMost = true;

Open in new window


that should keep your first form on top
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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