TabStrip and "Error creating window handle Win32Exception"

Docking/MDI for Windows Forms Forum

Posted 17 years ago by Roger Rong
Version: 2.0.92
Avatar
We build a complicate user control using the TabStrip with many TextBoxes in it and experience the program crashing with “System.ComponentModel.Win32Exception: Error creating window handle” after creating a certain amoumt of that controls.

To isolate the problem, we built simple WinForm program in which there is a dummy usercontrol using an Actipro TabStrip with two tab pages and placing 100 text boxes in each page. The testing program crashes with the above exception after creating about 50 usercontrols.

We were suspecting that was because it runs out resource, so we built another dummy usercontrol by putting 200 textboxes in a MS TabControl instead of the Actipro TabStrip, but we could create hundreds of instances of this usercontrol without crashing.

We could not understand why the TabStrip has such a big scalability difference from the MS TabControl. In addition to change our design to reduce the number of text boxes in the usercontrol, any other thing we could do to resolve the problem?

Our system is VS2005 with UIStudio 1.5.43. We also tested the latest UIStudio 2.0 trial version with the same result.

Following are some of our testing code:

    /// <summary>
    /// A user control using Actipro tabstrip
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();

            //Add some text boxes to the tab pages.
            for (int i = 0; i < 100; i++)
            {
                TextBox boxForPage1 = new TextBox();
                this.tabStripPage1.Controls.Add(boxForPage1);
                TextBox boxForPage2 = new TextBox();
                this.tabStripPage1.Controls.Add(boxForPage2);
            }
        }
    }

    /// <summary>
    /// A user control using MS tabcontrol
    /// </summary>
    public partial class UserControl2 : UserControl
    {
        public UserControl2()
        {
            InitializeComponent();

            for (int i = 0; i < 100; i++)
            {
                TextBox boxForPage1 = new TextBox();
                this.tabPage1.Controls.Add(boxForPage1);

                TextBox boxForPage2 = new TextBox();
                this.tabPage2.Controls.Add(boxForPage2);
            }
        }
    }

    public partial class Form1 : Form
    {
        private int _MSTotal = 0;
        private int _ActiproTotal = 0;
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Creates UserControl2 - MS tab control
        /// </summary>
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                UserControl2 theUserControl = new UserControl2();
            }

            _MSTotal += 5;
            this.textBox2.Text = _MSTotal.ToString();
        }

        /// <summary>
        /// Creates UserControl1 - Actipro tabstrip. 
        /// Systems crashes with the System.ComponentModel.Win32Exception: Error creating window handle 
        /// after creating about 50 UserControl1s
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                UserControl1 theUserControl = new UserControl1();
            }
            _ActiproTotal += 5;
            this.textBox1.Text = _ActiproTotal.ToString();
        }
    }

Comments (7)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Roger,

Can you please email over your sample project? Thanks!


Actipro Software Support

Posted 17 years ago by Roger Rong
Avatar
It has sent to the 'support@actiprosoftware.com'.

Thanks.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks Roger, we've been doing some intense debugging on this and believe we found what was causing it. When getting a Graphics object to use for measuring from a call to Control.CreateGraphics, it appears that something down in Microsoft's code wasn't releasing a reference to the Graphics object even though our code disposed it properly. So the more controls that were created, the heap memory usage increased.

We've changed our code to use a Bitmap for getting a Graphics instead. This seems to resolve the memory issue thus far and actually has really increased performance as well. So startup times for UIStudio controls seems to be much faster too! :)

This has required an update to the WinUICore library. I will email you now to arrange for you to test the update to ensure you see what we are seeing.


Actipro Software Support

Posted 15 years ago by miki
Avatar
Hi guys.
I am facing the same problem with a custom Tab control. What was the solution?
Posted 15 years ago by Rakesh Sinha
Avatar
Hi Roger,
We are facing the same error.
We need your help urgently.Kindly Help!
Can you please also email over your sample project to reproduce the problem? Thanks

The Stack Trace looks like this:
---------------------------------
Error Message: Error creating window handle.
Method which causes the error: CreateHandle
Source: System.Windows.Forms
Comments: WinUserControlBase.SaveData
Place where it occured: at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.CreateGraphicsInternal()
at System.Windows.Forms.Control.CreateGraphics()
at cam.WinUserControl.MessageBox.set_Message(String Value)
at cam.WinUserControl.MessageBox.Show(Control focusControl, String message, String caption, MessageBoxButtons buttons, Icon icon, MessageBoxDefaultButton defaultButton)
at cam.WinUserControl.appUtil.App.ShowAndLogError(Control focusControl, Exception ex, String caption)
at cam.WinUserControl.Building.LoadPanel(Int32 index)
at cam.WinUserControl.Building.GetTabStripPanelControl(Int32 index)
at cam.WinUserControl.WinUserControlBase.GetTabStripPanelRow(Int32 index)
at cam.WinUserControl.Building.UpdateData()
at cam.WinUserControl.WinUserControlBase.SaveData(Boolean raiseEventOnSuccess)

[Modified at 01/12/2009 02:58 AM]

[Modified at 01/12/2009 03:01 AM]
Posted 15 years ago by Roger Rong
Avatar
Rakesh, I wuold need your Email for sending over the test sample.
Posted 15 years ago by Rakesh Sinha
Avatar
Hi Roger,
I'm glad to receive a timely reply from you.Thank you.
My mail id is sms.sinha@gmail.com
Kindly mail me the sample project.

I would also like to tell you further on the problem we are facing.
1.We are loading WinForms in asp.net webpage.
2.We are loading the winform through a javascript as ActiveX object using Object
tag,Classid etc..
3.This Winform dll is loaded repeatedly since we navigate through next records,the
same page being loaded again and again the primary keys passed as params to the
winform varies with every movement to next record..
4. The crash occurs after we have navigated about 20+ records.
5.So there is definetly a leakage/limit saturation happens which leads to the crash.
6.Note!--We do have user controls loaded in the WinForm.

Hearing from you on this scenario would be great.
Thanks for your time and help.
Rakesh
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.