CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Question Does it make sense top new-up pens and brushes in OnPaint() every time it's called?

    Folks,

    I need to make a fairly simple WinForms custom control. It will have about hundred or so graphics shapes (lines, circles). Little to no animation. At the moment of writing, I don't expect it to be very graphics intensive. At the same time, I don't have experience with drawing custom controls.

    I've following this tutorial: Creating a professional looking GDI+ drawn custom control. I've noticed that some brushes in this tutorial are member variables (fields) of the control, and those are initialized once. Other brushes and pens are newed-up every time OnPaint() is called and disposed.

    Is it okay to new-up pens and brushes in OnPaint() every time it's called? Does that make sense?

    Any suggestion, insight or reference is really appreciated!

    Cheers,
    - Nick

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Does it make sense top new-up pens and brushes in OnPaint() every time it's calle

    Change some of the fields to different properties, and I'd bet it doesn't run the same. Who calls what, and with what scope, is in effect!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured