如何在一个WinForm中调用方法到另一个WinForm

如何在一个WinForm中调用方法到另一个WinForm

问题描述:

hai ..





如何使用c#.net
$ b将一个Winform中的方法调用到另一个Winform $ b

EX



from1

.....


Getmethod();



....





我想在From2中调用相同的方法



form2

......



Getmethod();



....





谢谢和收藏





venkat

hai..


How to call method in one Winform to another Winform using c#.net

EX

from1
.....

Getmethod();

....


I want to call same method in From2

form2
......

Getmethod();

....


Thanks&Reragds


venkat

或者如果GetMethod是静态的并且是公共的,你可以通过Form2.GetMethod()
Or if GetMethod is static and public you can call it by Form2.GetMethod()


来调用它。你需要在form1中引用form2(并且表单2中的Getmethod()必须是公共的)。
You need to have a reference to form2 in form1 (and Getmethod() in form 2 must be public).


首先将Form1中的GetMethod()声明为public.Then创建该Form1的对象并调用您想要调用的方法(确保你的GetMethod()不是静态方法),否则调用d直接bt Form1.GetMethod()。
First off all declare The GetMethod() in Form1 as public.Then create object of that Form1 and call the method where ever you want to call (Make sure k your GetMethod() is not a static method),else call directly bt Form1.GetMethod().