Click here to Skip to main content
15,909,539 members
Home / Discussions / C#
   

C#

 
GeneralRe: Displaying AOL .art file Pin
cgcrute11-Apr-05 11:04
cgcrute11-Apr-05 11:04 
GeneralRe: Displaying AOL .art file Pin
Heath Stewart12-Apr-05 8:15
protectorHeath Stewart12-Apr-05 8:15 
GeneralRe: Displaying AOL .art file Pin
cgcrute12-Apr-05 8:37
cgcrute12-Apr-05 8:37 
Generalconstant WM_PAINT messages Pin
jcl55515-Oct-04 5:00
jcl55515-Oct-04 5:00 
GeneralRe: constant WM_PAINT messages Pin
Stanciu Vlad15-Oct-04 5:11
Stanciu Vlad15-Oct-04 5:11 
GeneralRe: constant WM_PAINT messages Pin
jcl55515-Oct-04 5:49
jcl55515-Oct-04 5:49 
GeneralRe: constant WM_PAINT messages Pin
Brian Nottingham15-Oct-04 6:45
Brian Nottingham15-Oct-04 6:45 
GeneralRe: constant WM_PAINT messages Pin
Heath Stewart15-Oct-04 6:31
protectorHeath Stewart15-Oct-04 6:31 
WM_PAINT is sent for many reasons, and the best way to optimize your code is to honor the PaintEventArgs.ClipBounds property passed to OnPaint. Only draw what's necessary.

Overriding WndProc to handle painting is almost never the right way to handle user painting. Instead, you call SetStyle in the constructor and override OnPaint like so:
public MyControl()
{
  SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint,
    true);
  // ...
}
// ...
protected override void OnPaint(PaintEventArgs e)
{
  // ...
  // Call or don't call base.OnPaint(e) depending on the circumstances
}
Control.WndProc already handles the WM_PAINT messages and wraps the arguments necessary for painting in the PaintEventArgs and disposes the Graphics object when OnPaint returns.

If you want double-buffering for your custom drawing code, also OR the ControlStyles.DoubleBuffer enumeration with SetStyle in the example source above.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralNEED A COMPRESSION PROGRAM IN C# Pin
manivannan.p15-Oct-04 4:58
manivannan.p15-Oct-04 4:58 
GeneralRe: NEED A COMPRESSION PROGRAM IN C# Pin
Heath Stewart15-Oct-04 6:39
protectorHeath Stewart15-Oct-04 6:39 
Generaltic tac toe "bot" Pin
Pyro Joe15-Oct-04 4:38
Pyro Joe15-Oct-04 4:38 
GeneralRe: tic tac toe "bot" Pin
Heath Stewart15-Oct-04 6:43
protectorHeath Stewart15-Oct-04 6:43 
GeneralHost app in C# Pin
MBGeorge15-Oct-04 4:22
MBGeorge15-Oct-04 4:22 
GeneralRe: Host app in C# Pin
Gavin Jeffrey15-Oct-04 4:31
Gavin Jeffrey15-Oct-04 4:31 
GeneralRe: Host app in C# Pin
Dave Kreskowiak15-Oct-04 6:45
mveDave Kreskowiak15-Oct-04 6:45 
GeneralRe: Host app in C# Pin
Heath Stewart15-Oct-04 6:54
protectorHeath Stewart15-Oct-04 6:54 
Generaltrying to write to a log file in destructor Pin
Gavin Jeffrey15-Oct-04 4:13
Gavin Jeffrey15-Oct-04 4:13 
GeneralRe: trying to write to a log file in destructor Pin
Anonymous15-Oct-04 4:17
Anonymous15-Oct-04 4:17 
GeneralRe: trying to write to a log file in destructor Pin
Gavin Jeffrey15-Oct-04 4:27
Gavin Jeffrey15-Oct-04 4:27 
GeneralRe: trying to write to a log file in destructor Pin
Colin Angus Mackay15-Oct-04 4:53
Colin Angus Mackay15-Oct-04 4:53 
GeneralRe: trying to write to a log file in destructor Pin
Gavin Jeffrey15-Oct-04 6:31
Gavin Jeffrey15-Oct-04 6:31 
GeneralRe: trying to write to a log file in destructor Pin
Colin Angus Mackay15-Oct-04 10:31
Colin Angus Mackay15-Oct-04 10:31 
GeneralRe: trying to write to a log file in destructor Pin
Gavin Jeffrey17-Oct-04 20:44
Gavin Jeffrey17-Oct-04 20:44 
GeneralRe: trying to write to a log file in destructor Pin
benjymous15-Oct-04 4:45
benjymous15-Oct-04 4:45 
GeneralRe: trying to write to a log file in destructor Pin
afinnell18-Oct-04 8:07
afinnell18-Oct-04 8:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.