Question

I am using CAB and infragistics in winforms application, in a form I have some splitters and user controls with grids, buttons, labels... inside this splitters, when the form is opened in runtime, the user controls are not painted correctly, this problem is known for win7 x64 as described here controls inside Split Container paint issue on Windows 7 and here on this archive link from the Component Factory website cache . The workaround provided in the above topics consist of overriding the OnSizeChanged method :

protected override void OnSizeChanged(EventArgs e)
    {
        if (Handle != null)
            BeginInvoke((MethodInvoker)delegate
            { base.OnSizeChanged(e); });
    }

the problem with this solution when using the CAB that this method is called when initializing form components from constructor (InitializeComponent called from constructor ) and OnLoad method is called when Handle property is accessed because it is created if its value is null,

protected override void OnLoad(EventArgs e)
    {            
        _presenter.OnViewReady();
        base.OnLoad(e);            
    }

Here the _presenter is not set yet and its value is null and an axception is thrown.

What can I do for this issue?

Regards.

Was it helpful?

Solution

A simple solution may be to have a field (_isInitilizeCompleted) to indicate if the InitilizeComponent method has completed and modify the OnSizeChanged method to be as follows:

 protected override void OnSizeChanged(EventArgs e)
 {
     if (Handle != null && _isInitilizeCompleted)
         BeginInvoke((MethodInvoker)delegate
         { base.OnSizeChanged(e); });
 } 

I haven't tested but it should work, unless of course OnSizeChanged needs to be called during InitializeComponent.

OTHER TIPS

The idea of using a flag works fine! just the flag test must be done before testing the Handle property :

protected override void OnSizeChanged(EventArgs e)
    {
        if (_isInitilizeCompleted && Handle != null)
            BeginInvoke((MethodInvoker)delegate
            { base.OnSizeChanged(e); });
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top