Error Creating Window Handle

harvid

Member
Joined
Dec 8, 2004
Messages
18
Programming Experience
1-3
Hi,

I'm my project i'm getting "Error Creating Window Handle" message on continuous button Click. I haven't used MDI forms. Instead i'm displaying Panel( Includes all controls similar to displaying a form )for each and every button Click.

I'm not able to dispose a panel cos i'm calling one panel from another.

Pls provide a solution for that. Need urgent

Thanx in advance.

Harvid
 
Hey harvid,

I'm afraid I'm not sure exactly what's causing your problem but I've recently had a similar problem when dynamically creating instances of usercontrols and not completely disposing them. I can't remember the exact number, but Windows only allows a certain number (rather a lot though, in the thousands I believe) of controls per process before you will recieve the error you've described. If you're creating the panels programmatically, ensure that you're not getting stuck in a loop of some kind thus creating many more panels than intended. If you can, maybe you could post some source code. I realise this is not your problem but as a note when disposing of controls you must make sure that every reference to that control is disposed incuding event handlers etc.

Hope you get this sorted out. Keep us posted.

Regards.
 
Hi Badger,

In my Main Form, i'm having a default panel (pnlMain) and 15 to 20 buttons
In each button click, i'm displaying the respective panels in place of default panel in Main Form.
Like this,
private void btnFirst_Click(object sender, System.EventArgs e)
{
FrmFirst ObjFirstForm = new FrmFirst();
try
{
pnlMain.Controls.Clear();
pnlMain.Controls.Add( ObjFirstForm.DisplayPanel );
}
catch( Exception ex )
{

}
}

FrmFirst:
-------------
public Panel DisplayPanel
{
get
{
return this.pnlFirst;
}
}

On continuous click of btnFirst, i'm getting "Error Creating Window Handle" exception and my Application goes off but it is there in Task Manager

Thanks,

Harvid
 
Hey,

I think I see what you're trying to achieve now, I use panels in a similar manner to create wizards. However there are a couple of problems here. The first thing, and what is causing your main error is that when you call Panel.Controls.Clear the controls that were in the panel are not actually disposed, thus eventually Windows will have a fit! Previous to hitting this problem myself I presumed that Controls.Clear would automatically call dispose but it doesn't. Rather than trying to dispose all these controls (buttons etc.. which would be a nightmare) I would advise you to place all of the panels you wish to show on the main form overlapping at startup (you can do this either programatically or at design time) and use the BringToFront or Visible functions of the Panels to select them.

Hope this helps

Regards.
 
Hi,

Keeping all panels in One Form makes it heavier and heavier when i need to create more Panels in future.

Thanks and Regards,

Harvid
 
Back
Top