调用另一种表单方法 - SmartDevice Window应用程序 [英] Call Another form method - SmartDevice Window app

查看:66
本文介绍了调用另一种表单方法 - SmartDevice Window应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发一些基于窗口的应用程序(C#)它的移动设备应用程序。我有两种形式,如Form1()和Form2()和Form1()有一种方法



  public   void  Test()
{
MessageBox.Show( Hello Parent);
}





我想从Form2()调用此方法但不创建Form1的任何对象( )。我怎么能这样做。



先谢谢。

Vivek

解决方案

< blockquote>你不能,不是那样的。该方法需要一个类实例。您可以将其设为 static

  public   static   void  Test()
{
MessageBox.Show( Hello Parent);
}

但是你不能从Test方法中访问任何表单字段,属性或其他非静态方法。


Hi I am working on some window based application(C#) its a Mobile device application.I have two forms like Form1() and Form2() and Form1() has one method

public void Test()
       {
           MessageBox.Show("Hello Parent");
       }



I want to call this method from Form2() but without creating any object of Form1(). How can I do that.

Thanks in Advance.
Vivek

解决方案

You can't, not like that. That method needs a class instance. You could make it static:

public static void Test()
   {
   MessageBox.Show("Hello Parent");
   }

But then you can't access any of the form fields, properties or other non-static methods from within the Test method.


这篇关于调用另一种表单方法 - SmartDevice Window应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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