Link to home
Start Free TrialLog in
Avatar of AbhilashN
AbhilashN

asked on

Out of memory exception in design time (window form ,C#, .NET framework 1.1)

Hi ,
I am getting out of memory exception issue in design time ,whenever tried to open window forms coded in C#.After i implemented Onpaint method overriding to change forecolor of textbox in disable mode ,it started giving troubles like whenever user want to open a form (design time) it pops the error outofmemory exception. In runtime everything is fine and working perfect but just in design time.

Any suggestions please?I am using .NET framework 1.1 , VS2003.I am using custom control for this.

Thanks
Avatar of AlexFM
AlexFM

Paint event of user control is called at design time. Possibly it contains some bug. Can you show your code?
You can set some MessageBoxes in the Paint event handler to get exaclty where it is failing. Do not leave them in the code for later however
Actually, adding MessageBox to Paint event handler can cause endless recursion. In this case it is better to use Trace. Or debug user control Paint handler using second Visual Studio instance.
Trace would not work design time (as well as I know). However MessageBox works and you could just add it until you find the line which causes the problem. What I mean is just set it somewhere and check if it gets shown. If yes - move it further down, otherwise up and so on until the line is identified. Something like a binary search :-)
Trace is always executed when code runs. However, Visual Studio which hosts user control doesn't show trace output from code executed in this control. This can be done using DebugView utility from www.sysinternals.com.
Avatar of AbhilashN

ASKER

This is my code -

//Override paint method to change forecolor of TextBox when it is in disable mode.



Constructor 1()

{

 this.SetStyle( ControlStyles.UserPaint, true);// I called this in constructors of the class.

}


Constructor 1()

{

 this.SetStyle( ControlStyles.UserPaint, true);// I called this in constructors of the class.

}




protected override void OnPaint(PaintEventArgs e)
            {
                  if(this.Enabled==false)
                  {
                        
                        this.SetStyle( ControlStyles.UserPaint, true);
                        SolidBrush drawBrush = new SolidBrush( color.black );
                        e.Graphics.DrawString( Text, Font, drawBrush, 1f, 1f );
                        this.BackColor=System.Drawing.SystemColors.Control;
                        
                  }
                  else if(this.Enabled==true)
                  {
                        this.SetStyle(ControlStyles.UserPaint,false);
                        SolidBrush drawBrush = new SolidBrush( ForeColor );
                        e.Graphics.DrawString( Text, Font, drawBrush, 1f, 1f );
                                                //base.Enter(e);
                        //base.OnLeave(e);
                        
                         base.Refresh();
                        //base.OnPaint(e);
                  }
                      
                                this.SetStyle(ControlStyles.UserPaint,true);
                      base.OnPaint(e);
                    
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Without questioner's feedback, I suggest split.