More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

How to fix "Top-level control cannot be added to a control" Options · View
hong
Posted: Tuesday, September 21, 2010 1:14:49 PM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 335
Points: 711
Location: Australia
The error message "Top-level control cannot be added to a control" is self-explanatory.

It's easy to fix. Before you add a top-level control to a control, you need to set top level to false:

Code:
this.panel1.Toplevel = false;
or
this.panel1.SetTopLevel(false);


Then you need to show the control, using Show(), after it's added to a control.

You can test whether the control is a top level control:
Code:
bool bTopLevel = panel1.TopLevel;
bool bTopLevel = panel1.GetTopLevel();


When the control is not a top level control, it looses all the form level events such as Close().

Since the control is no longer the top level control, it doesn't look like a separate form. To compensate for this, you can add all your controls in a Panel.
Sponsor
Posted: Tuesday, September 21, 2010 1:14:49 PM
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.167 seconds.