如何在一个WinForm中调用方法到另一个WinForm [英] How to call method in one WinForm to Another WinForm

查看:467
本文介绍了如何在一个WinForm中调用方法到另一个WinForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai ..





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

EX



from1

.....

< br $>
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().


这篇关于如何在一个WinForm中调用方法到另一个WinForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆