Solved

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

Posted on 2006-10-19
11
832 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:AbhilashN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
11 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17771758
Paint event of user control is called at design time. Possibly it contains some bug. Can you show your code?
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 17771938
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
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17771947
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.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 20

Expert Comment

by:TheAvenger
ID: 17771951
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 :-)
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17771985
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.
0
 

Author Comment

by:AbhilashN
ID: 17773775
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);
                    
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17774366
this.SetStyle( ControlStyles.UserPaint, true);
this.BackColor=System.Drawing.SystemColors.Control;

These lines require redrawing of the control, this causes control to be redrawn immediately after Paint event exits. Find another place to do this. I think Control.EnableChanged event is appropriate placeis.

base.Refresh();
Forces the control to invalidate its client area and immediately redraw itself and any child controls. Never call Refresh function from Paint event handler - this creates endless loop.

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17964525
Without questioner's feedback, I suggest split.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question