Hallo,
I just can't get this one figured out. I have a frmMain which contains some logic which controlls my app.
1.frmMain loads
[STAThread]
public static void Main() {
Application.Run(new frmMain());
}
2.frmMain calles StartUp() which looks something like this:
private void frmMain_Load(object sender, System.EventArgs e) {
this.StartUp();
}
private void StartUp() {
this.Hide();
//create sub-form.
if( users.IsFirstRegEver() == 1 ) {
frmFirstEver frmFE = new frmFirstEver();
frmFE.TopLevel = false;
frmFE.parent = this;
frmFE.Show();
frmFE.Activate();
frmFE.TopMost = true;
} else if( users.IsFirstToday() == 1 ) {
frmFirstToday frmFT = new frmFirstToday();
frmFT.TopLevel = false;
frmFT.Parent = this;
frmFT.Show();
frmFT.Activate();
frmFT.TopMost = true;
} else {
frmShareTime frmST = new frmShareTime();
frmST.TopLevel = true;
frmST.Parent = this;
frmST.Show();
frmST.Activate();
frmST.TopMost = true;
}
}
3. Doing things this way generates error message listed below.
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot add a top level control to a control.
I choose a hidden main form for three reasons:
1. It handles StartUp, defining which forms should be displayed.
2. It handles a wait sequence, run whenever the user hits a wait button in any of my three sub-forms.
3. It handles my system tray icon and menu.
Has anyone any idea why I am getting this error, or could point me in the direction of other ways of solving this problem.
Maybe I am going at this the wrong way??
Any advice would be greatly appreciation!
Best regards
Eirik Hesthamar,
Norway
I just can't get this one figured out. I have a frmMain which contains some logic which controlls my app.
1.frmMain loads
[STAThread]
public static void Main() {
Application.Run(new frmMain());
}
2.frmMain calles StartUp() which looks something like this:
private void frmMain_Load(object sender, System.EventArgs e) {
this.StartUp();
}
private void StartUp() {
this.Hide();
//create sub-form.
if( users.IsFirstRegEver() == 1 ) {
frmFirstEver frmFE = new frmFirstEver();
frmFE.TopLevel = false;
frmFE.parent = this;
frmFE.Show();
frmFE.Activate();
frmFE.TopMost = true;
} else if( users.IsFirstToday() == 1 ) {
frmFirstToday frmFT = new frmFirstToday();
frmFT.TopLevel = false;
frmFT.Parent = this;
frmFT.Show();
frmFT.Activate();
frmFT.TopMost = true;
} else {
frmShareTime frmST = new frmShareTime();
frmST.TopLevel = true;
frmST.Parent = this;
frmST.Show();
frmST.Activate();
frmST.TopMost = true;
}
}
3. Doing things this way generates error message listed below.
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot add a top level control to a control.
I choose a hidden main form for three reasons:
1. It handles StartUp, defining which forms should be displayed.
2. It handles a wait sequence, run whenever the user hits a wait button in any of my three sub-forms.
3. It handles my system tray icon and menu.
Has anyone any idea why I am getting this error, or could point me in the direction of other ways of solving this problem.
Maybe I am going at this the wrong way??
Any advice would be greatly appreciation!
Best regards
Eirik Hesthamar,
Norway