如何创建窗口形式的运行时对象 [英] how to create a Runtime Object of window form

查看:127
本文介绍了如何创建窗口形式的运行时对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将此对象作为参数传递..

当前状态.
例如:-acb(第一个参数,第二个参数,此)
这是当前表单的用法....
但是在我的项目中有多重形式.
那么如何才能以"this"的形式传递multipul形式.

目的.
我想使用形式的控件.

I want to pass this object as a parameter..

current status.
ex:- acb(first parameter,second parameter,this)
this is use for the current form....
but in my project there is multipule forms.
so how can pass the multipul form''s in plase of "this".

purpos.
i want to use the controls of the form.

推荐答案

问题中显示的方法acb 中的最后一个parameter 可以定义为类型System.Windows.Forms.Form ,以便this 关键字给出的当前形式和任何其他现有形式都可以作为argument 与此parameter相对的形式传递给此方法.
The last parameter in the method acb shown in the question can be defined as type System.Windows.Forms.Form, so that the current form given by this keyword and any other existing form can be passed to this method as an argument against this parameter.


使用您总是在谈论您所在类的当前实例-在您的情况下是表单.因此,当您使用this作为参数调用方法时,将传递当前正在使用的任何实例.

When you use this you are always talking about the current instance of whatever class you are in - in your case a form. So when you call a method using this as a parameter, you pass whichever instance if currently in use.

public class MyForm : Form
   {
   ...
   public void DoSomething()
      {
      MyStaticClass.MyMethod(this);
      }
   ...
   }

MyForm mf1 = new MyForm();
MyForm mf2 = new MyForm();
mf1.DoSomething();
mf2.DoSomething();

会将MyForm的两个不同实例传递给静态MyMethod方法.

因此,您已经可以传递多个表单了!

Would pass two different instances of MyForm to the static MyMethod method.

So you already do pass multiple forms!


如果必须创建表单,然后将其对象传递给函数,那么也许可以这样做

可以说形式:FormA,FormB

修改功能,如:

acb(first, second, FormA frmA, FormB frmB)

然后将表单对象传递为:

If you have to create the forms and then pass its object to the function then perhaps you can do this

lets say forms: FormA, FormB

Modify the function like:

acb(first, second, FormA frmA, FormB frmB)

then pass the form objects as:

FormA fa = new FormA();
FormB fb = new FormB();

acb(first, second, fa,fb);



请提供更多详细信息,以便我提出更好的方法.



Please provide more details so that I can suggest better ways of doing this.


这篇关于如何创建窗口形式的运行时对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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