Solved

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

Posted on 2006-10-19
11
817 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
Iterate a dictionnary to change values 4 53
XML & .net 5 40
Not showing JavaScript in the list 5 37
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now