Solved

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

Posted on 2006-10-19
11
810 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

20 Experts available now in Live!

Get 1:1 Help Now