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:' Draw everything g.Clear(Me.BackColor)
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.Code:Public Sub New() Me.InitializeComponent() Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.Opaque Or ControlStyles.OptimizedDoubleBuffer, True) End Sub
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




Reply With Quote