Handles syntax in C# - must be easy

  • Thread starter Thread starter Ed West
  • Start date Start date
E

Ed West

I can't find this answer anywhere! I am making a class that inherits
from StatusBar control and I want to convert this function to C#...

Private Sub Reposition(ByVal sender As Object, _
ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) _
Handles MyBase.DrawItem
....
End Sub

i can't override the DrawItem method, nor can I make an event handler with

this.DrawItem += new EventHandler ...

how can I do this?

it is from this project:

http://www.codeproject.com/vb/net/ProgressStatus.asp

thanks!

Ed
 
nevermind, i figured it out... the this.DrawItem += had to be in a method.

in the constructor:

this.DrawItem += new
StatusBarDrawItemEventHandler(this.ProgressStatus_DrawItem);
private void ProgressStatus_DrawItem(object sender,
StatusBarDrawItemEventArgs sbdevent ) {
...
}

thanks anyway!

Ed
 
If you are handling the base class's event in the derived class, you
might want to consider overriding the OnDrawItem() method instead. Even
if you want to do things _in addition to_ what your base class does
when the DrawItem event happens, you can still do it in an overridden
method. If you want your derived class to do things _instead of_ what
your base class does when the DrawItem event happens, overriding
OnDrawItem() is the only way to achieve this.

I suggest this because it's a more usual idiom in the derived class:
override the appropriate On...() methods, rather than subscribing to
the parent's events.
 
Back
Top