Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing ThisForm to a method
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01527250
Message ID:
01527260
Views:
53
>I have a GeneralPurpose Method where I do a lot of processing, all to do with Forms, but the Method can be called from different Forms. How do I pass the Current Form to amethod
>
>e.g. In a Click Button I want to: MyMethod(Thisform) (In VFP terms)
>
>What is the syntax to do this in C#
>
>Tia
>Gerard


Hi there, if your *Method* only accesses the basic methods and properties of a WinForm then you can just pass *this* as a parameter e.g. ( assuming myobj is an instance of the class containing *MyMethod* ) myobj.MyMethod(this) - and the signature of MyMethod would be:
public void MyMethod(System.Windows.Forms.Form frm)
{
    // Do whatever with frm
}
However if your form classes have custom properties and methods you would need to have those classes implement a common interface containing your methods and properties and pass an instance of the form as *WhateverYouCallYourInterface* lets call it *IMyFormInterface* - your MyMethod signature would then be
public void MyMethod(IMyFormInterface frm)
{
    // Do whatever with frm
}
Regards,
Peter J. Kane



Pete
Previous
Reply
Map
View

Click here to load this message in the networking platform