Solved

c# windows app open another form on load

Posted on 2011-03-23
5
749 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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