By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

vb.net to c# conversion help please

P: n/a
Hi everyone, i have a vb.net program ive converted most of the code but
i know events dont translate well, the original vb.net code uses
withevents and .handles and i can't get the events in c# to work 100%
they seem to hook up ok but when the eventhandler is called from the
method its null and fails.
or maybe im reading it wrong?
public abstract class Page : IDisposable
{
protected ListControl mainList;
public virtual void DisplayPage(ref frmMain myForm)
{
this.mainList.LeaveControl += new
dmControls.ListControl.LeaveControlEventHandler(ma inList_LeaveControl);

this.mainList.Selected += new
dmControls.ListControl.SelectedEventHandler(mainLi st_Selected);
this.mainList.SelectionChanged += new
dmControls.ListControl.SelectionChangedEventHandle r(mainList_SelectionChang***ed);


}
protected delegate void
MainListLeaveControlEventHandler(dmControls.Direct ion direction);
private MainListLeaveControlEventHandler MainListLeaveControlEvent;
protected event MainListLeaveControlEventHandler MainListLeaveControl
{
add { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate. Combine(MainListLeaveCont***rolEvent,
value); }
remove { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate. Remove(MainListLeaveContr***olEvent,

value); }

}
protected delegate void MainListSelectedEventHandler(string sSelected,
object Data);
protected MainListSelectedEventHandler MainListSelectedEvent;
protected event MainListSelectedEventHandler MainListSelected
{
add { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Comb ine(MainListSelectedEvent***,
value); }
remove { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Remo ve(MainListSelectedEvent,

value); }

}
protected delegate void MainListSelectionChangedEventHandler(string
sSelected, object Item);
private MainListSelectionChangedEventHandler
MainListSelectionChangedEvent;
protected event MainListSelectionChangedEventHandler
MainListSelectionChanged
{
add { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Deleg ate.Combine(MainListSelec***tionChangedEvent,
value); }
remove { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Deleg ate.Remove(MainListSelect***ionChangedEvent,

value); }

}
private void mainList_LeaveControl(Direction direction)
{
..........................
}
private void mainList_Selected(string sSelected, object Data)
{
if (MainListSelectedEvent != null)
MainListSelectedEvent(sSelected, Data);
}
}
DisplayPage is then overridden and called from different type of pages
that inherit from page.

its the MainListSelectedEvent thats null when i try and call it.
any help really appreciated!
thanks.
bryan

Mar 16 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<ht*******@hotmail.com> wrote:
Hi everyone, i have a vb.net program ive converted most of the code but

i know events dont translate well, the original vb.net code uses
withevents and .handles and i can't get the events in c# to work 100%


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(The code you posted is neither short, nor complete.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.