I can find examples on how to override the form paint event but how would I go about overriding a panel paint event?
Any help appreciated.
Printable View
I can find examples on how to override the form paint event but how would I go about overriding a panel paint event?
Any help appreciated.
You don't override events. You handle events and you override methods. If you want to provide custom painting functionality for a particular Panel on a particular form then you can handle its Paint event, just like you would for the form itself:Alternatively, and especially if you want to provide this same functionality for more than one Panel on more than one form, then you should declare your own class, inherit the Panel class and override its OnPaint method. It is the OnPaint method that raises the Paint event, so you invoke the standard functionality first and then you provide your own custom logic, e.g.VB Code:
Public Class Form1 Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint 'Provide your own custom logic here, e.g. draw a diagonal line. e.Graphics.DrawLine(Pens.Black, 0, 0, Me.Width, Me.Height) End Sub End ClassYou then add instances of your own PanelEx class to your forms instead of vanilla Panel objects.VB Code:
Public Class PanelEx Inherits Panel Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) 'Invoke the standard functionality of the Panel class, including raising the Paint event. MyBase.OnPaint(e) 'Provide your own custom logic here, e.g. draw a diagonal line. e.Graphics.DrawLine(Pens.Black, 0, 0, Me.Width, Me.Height) End Sub End Class
Thanks for the reply and my apologies for the nomenclature error.
I am plotting a scrolling graph on a panel and I needed to override the Paint method in order to eliminate flicker.