Results 1 to 17 of 17

Thread: [RESOLVED] What happened to simple speed?

Threaded View

  1. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: What happened to simple speed?

    Code:
     
            ' Draw everything
            g.Clear(Me.BackColor)
    This is superfluous and probably reduces performance. The form client area has already been cleared to the Backcolor in MyBase.OnPaintBackground. There is no need to do it again in the OnPaint sub or in the Paint event handler. It forces the entire client area to be repainted instead of just the lines to be drawn.

    Code:
    Public Sub New()
        Me.InitializeComponent()
    
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or
                   ControlStyles.UserPaint Or
                   ControlStyles.Opaque Or
                   ControlStyles.OptimizedDoubleBuffer, True)
    End Sub
    This is obsolete and possibly superfluous. The SetStyles statements have been replaced by the DoubleBuffered property since VB2005. You can set it in the Designer or for example in the Load event sub. Besides, it doesn't affect the speed of painting but prevents flickering if the image changes rapidly.

    Replacing the Paint event handler by an OnPaint sub obscures matters. Normally you would use OnPaint in a class definition but handle the Paint Event in an instance. Both of these are possible for a form added in Visual Studio because it is both a class and a default instance of that class. MyBase.Paint in the OnPaint sub raises the Paint event, so it is not going to make the least difference to performance.

    BB

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