C
c#2006user
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(mainList_LeaveControl);
this.mainList.Selected += new
dmControls.ListControl.SelectedEventHandler(mainList_Selected);
this.mainList.SelectionChanged += new
dmControls.ListControl.SelectionChangedEventHandler(mainList_SelectionChanged);
}
protected delegate void
MainListLeaveControlEventHandler(dmControls.Direction direction);
private MainListLeaveControlEventHandler MainListLeaveControlEvent;
protected event MainListLeaveControlEventHandler MainListLeaveControl
{
add { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate.Combine(MainListLeaveControlEvent,
value); }
remove { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate.Remove(MainListLeaveControlEvent,
value); }
}
protected delegate void MainListSelectedEventHandler(string sSelected,
object Data);
protected MainListSelectedEventHandler MainListSelectedEvent;
protected event MainListSelectedEventHandler MainListSelected
{
add { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Combine(MainListSelectedEvent,
value); }
remove { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Remove(MainListSelectedEvent,
value); }
}
protected delegate void MainListSelectionChangedEventHandler(string
sSelected, object Item);
private MainListSelectionChangedEventHandler
MainListSelectionChangedEvent;
protected event MainListSelectionChangedEventHandler
MainListSelectionChanged
{
add { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Delegate.Combine(MainListSelectionChangedEvent,
value); }
remove { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Delegate.Remove(MainListSelectionChangedEvent,
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
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(mainList_LeaveControl);
this.mainList.Selected += new
dmControls.ListControl.SelectedEventHandler(mainList_Selected);
this.mainList.SelectionChanged += new
dmControls.ListControl.SelectionChangedEventHandler(mainList_SelectionChanged);
}
protected delegate void
MainListLeaveControlEventHandler(dmControls.Direction direction);
private MainListLeaveControlEventHandler MainListLeaveControlEvent;
protected event MainListLeaveControlEventHandler MainListLeaveControl
{
add { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate.Combine(MainListLeaveControlEvent,
value); }
remove { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate.Remove(MainListLeaveControlEvent,
value); }
}
protected delegate void MainListSelectedEventHandler(string sSelected,
object Data);
protected MainListSelectedEventHandler MainListSelectedEvent;
protected event MainListSelectedEventHandler MainListSelected
{
add { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Combine(MainListSelectedEvent,
value); }
remove { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Remove(MainListSelectedEvent,
value); }
}
protected delegate void MainListSelectionChangedEventHandler(string
sSelected, object Item);
private MainListSelectionChangedEventHandler
MainListSelectionChangedEvent;
protected event MainListSelectionChangedEventHandler
MainListSelectionChanged
{
add { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Delegate.Combine(MainListSelectionChangedEvent,
value); }
remove { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Delegate.Remove(MainListSelectionChangedEvent,
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