Solved

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

Posted on 2006-10-19
11
842 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
Technology Partners: 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!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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