Error in creating windows handle
"Error Creating Window Handle"
The general consensus found in most of these threads is that my application isn't disposing of various controls properly. However, that's not the case for me.
As far as I know, none of those values seem out of the ordinary. Also, I get this error when I try to load a form. It consists of a DotNetBar AdvTree with ~28 nodes. 26 of them have 2 cells, and the second cell has a hosted control using a DotNetBar TextBoxX. If I load any fewer number of nodes, the error goes away.
Am I missing something? I'm fairly certain that disposing objects isn't the issue as I encounter this problem when I load the form.
Here is the stack trace:
System.ComponentModel.Win32Exception (0x80004005): Error creating window handle.
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at DevComponents.AdvTree.AdvTree.Ú›()
at DevComponents.AdvTree.AdvTree.Ú“(Rectangle Ú‘, Rectangle Ú’)
at DevComponents.AdvTree.AdvTree.Ú()
at DevComponents.AdvTree.AdvTree.RecalcLayout()
at DevComponents.AdvTree.Node.OnDisplayChanged()
at DevComponents.AdvTree.Cell.OnSizeChanged()
at DevComponents.AdvTree.Cell.HostedControlSizedChanged(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
at System.Windows.Forms.Control.UpdateBounds()
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at DevComponents.DotNetBar.Controls.TextBoxX.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Answer:
With the custom controls, there is a Hosted Control property. The order of objects I was creating happened like this:
- Create a node
- Create a cell
- Create the hosted control
- Set the cell's hosted control property to the control in step 3.
- Add the cell to the node.Cells collection
- Add the node to the tree.
Since in step 4, the cell didn't have a parent, it was essentially just there. My speculation is that neither the hosted control nor the cell had a parent, so it couldn't properly locate these controls. Either way, I needed to set the parent of the hosted control to the form. This seemed to fix my problem:
Hosted Control ctrl.Parent = this;