Workaround for forcing the Paint Event in the Form Resize Event


By Diablo iii
Printer Friendly Version
View My Articles
10 Points
  

The Paint Event is not called in the Case of a Control's Resize Event. Read on to know the workarounds for this problem.



The Paint Event is not called in the Case of a Control's Resize Event. Read on to know the workarounds for this problem.

Many of us write the common graphics code in the Form's Paint event, for the benefits that the Paint Event handler provides access to the Graphics object and also that it is fired whenever the form is redrawn(first shown and restored from its minimized state).

But it fails,when the form is resized. The Paint event is not triggered in the case of a Form Resize.

To solve this problem you have two workarounds..

1) Use the handy Invalidate() Method which causes the paint message to be sent to the form As a result of this, the Paint handler is called.

2) Use the "ResizeRedraw" property of control(Form) to redraw itself when the control is resized. Set it it true either in the constructor or the Main() Method.

Please Note: 

When you call the Invalidate() method without any parameters, the Paint event is called for the entire area.

If only a particular portion of the control needs to be refreshed, then call it with a Rectangle parameter that specifies the               portion of the control, otherwise it would hit the performance of the application.




button
 
Article Discussion: Workaround for forcing the Paint Event in the Form Resize Event
Diablo iii posted at 20-Oct-08 07:20
Original Article

promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   

"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class
Manipulate file attributes in VB.NET
Forms Based Authentication Filtered Content Editor for SharePoint
How to create a Tree View of the Windows Folder and extract all the file-folder info.
How to use AssemblyInfo.cs file in win forms to provide much needed information on Assemblies
Sorting In Datagrid
Helper class to work with NativeMethods in the native api's
Silverlight Line Of Business Applications With Offline WPF Versions
C# : Database monitoring system using XML file
C# : Adding ComboBox to ListView SubItem
Sum of Numbers Captcha: Keeping it Simple
C# Create a Piechart for the specified Hard Disk Drive Utilization
Extension Methods for DataSet and DataTable that makes tasks easier
Accessing IIS Hosted WCF Services from PHP
Helper class that provides most commonly used Extension Methods for DateTime object
Helper class to work with a Status Bar in WPF.
Finding Unmatched Records in Dataset Tables Using Linq
Silverlight Toolkit: Autocomplete TextBox Stock Symbols and Chart
COOL Auto Complete textbox using javascript
Creating a Serializable Log Entry for Microsoft Enterprise Library to log to a Database
ASP.NET Searching Values in Datagrid