C
Colin Basterfield
Hi,
I'm trying to convert a VB.NET sample app I found to C# but the delegates
part has caught me out, I have a form which has the following delegates
defined:
public delegate void AddNewEmployee(Employee employee);
There is a method defined that uses this
private void OnAddNewEmployee(Employee employee)
{
lbEmployees.Items.Add(employee);
}
This method can to be passed into a number of forms and consequently has
private AddNewEmployee addNewEmp;
declared within the form class. There is an overloaded constructor which is
declared as:
public frmProgrammer(AddNewEmployee dele) : base()
{
InitializeComponent();
addNewEmp = dele;
}
Now the form that calls this does the following, or rather needs to do the
following:
private void btnAddProgrammer_Click(object sender, System.EventArgs e)
{
frmProgrammer frmProg = new frmProgrammer(OnAddNewEmployee);
frmProg.ShowDialog();
}
Unfortunately the compiler does not like this saying
C:\VSNet Dev\ClientWinApp\frmMain.cs(251): Method
'EmployeeExample.Form1.OnAddNewEmployee(EmployeeExample.Employee)'
referenced without parentheses
The VB.NET sample uses AddressOf, so can someone please tell me how I does
this in C#?
Many thanks, TIA
Colin B
I'm trying to convert a VB.NET sample app I found to C# but the delegates
part has caught me out, I have a form which has the following delegates
defined:
public delegate void AddNewEmployee(Employee employee);
There is a method defined that uses this
private void OnAddNewEmployee(Employee employee)
{
lbEmployees.Items.Add(employee);
}
This method can to be passed into a number of forms and consequently has
private AddNewEmployee addNewEmp;
declared within the form class. There is an overloaded constructor which is
declared as:
public frmProgrammer(AddNewEmployee dele) : base()
{
InitializeComponent();
addNewEmp = dele;
}
Now the form that calls this does the following, or rather needs to do the
following:
private void btnAddProgrammer_Click(object sender, System.EventArgs e)
{
frmProgrammer frmProg = new frmProgrammer(OnAddNewEmployee);
frmProg.ShowDialog();
}
Unfortunately the compiler does not like this saying
C:\VSNet Dev\ClientWinApp\frmMain.cs(251): Method
'EmployeeExample.Form1.OnAddNewEmployee(EmployeeExample.Employee)'
referenced without parentheses
The VB.NET sample uses AddressOf, so can someone please tell me how I does
this in C#?
Many thanks, TIA
Colin B