Handles syntax in C# - must be easy

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
 
E

Ed West

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
 
B

Bruce Wood

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top