Tracking.UI.MainWindows.VendorOrderLegDetailsForm.DisplayVendorDetails(this.FindForm(), (BHFreight.Tracking.BusinessObjects.VendorOrderLegDetail)_OrderLegDetail, delegate UpdateControl); |
How do i pass a delegate to this function signiture.....I dont know if the way i am doing this is the correct way can some one help me out /

how to make this function signiture pass a delegate
TkNeo
Well I want this delegate to listen for a form closing event to fire.....when that form closes i want my delegate to populate a control i have with some data.....this is the function that instantiates my form...now when this form closes i think i need to call this event so should i add it like so....
public static void DisplayVendorDetails(System.Windows.Forms.Form ParentForm, BHFreight.Tracking.BusinessObjects.VendorOrderLegDetail _VendorLeg)
{
Tracking.UI.MainWindows.VendorOrderLegDetailsForm frmVendorLeg = new VendorOrderLegDetailsForm();
frmVendorLeg._VendorDetail = _VendorLeg;
frmVendorLeg.LoadVendorObjectToForm();
frmVendorLeg.ShowDialog(ParentForm);
frmVendorLeg.OnClosing += MyDelegate
}
oscarg102941
You can create an object of delegate class something like this:
delegate void SomeDelegate (string data);
and then you can pass this delegate to your function like this:
Tracking.UI.MainWindows.VendorOrderLegDetailsForm.DisplayVendorDetails(this.FindForm(), (BHFreight.Tracking.BusinessObjects.VendorOrderLegDetail)_OrderLegDetail, SomeDelegate UpdateControl);
in vender details you can call this delegate using:
pivate void DisplayVendorDetails()
{
UpdateControl("SomeString");
//// Some code
}
where the original function reference by delegate looks like this:
private void ShowString(sting showString)
{
Console.WriteLine(showString);
}
And creattion of delgate will be like this before passing it to DisplayVenderDetails:
SomeDelegate someDelegate = new SomeDelegate(ShowString);
Tracking.UI.MainWindows.VendorOrderLegDetailsForm.DisplayVendorDetails(this.FindForm(), (BHFreight.Tracking.BusinessObjects.VendorOrderLegDetail)_OrderLegDetail, someDelegate );
Best Regards,
Rizwan
FERRAND
I think you dont need to pass delegate here in this situation. Just create and event handler for FormClosing on frmVEnderLeg and put it there like this:
frmVendorLeg.Closing += new System.Windows.Forms.FormClosingEventHandler(frmVendorLeg_Closing);
and here is:
public void frmVendorLeg_Closing(object sender, FormClosingEventArgs e)
{
/// Do your work here........
}
Still need to send delegate
Try this:
private delegate void FrmClosing(object sender, FormClosingEventArgs e);
create it's instance and pass this to function....
Best Regards,
Rizwan