从第一种形式中以第二种形式调用甲基 [英] Call mehtode in 2nd Form from 1st Form
本文介绍了从第一种形式中以第二种形式调用甲基的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个主要形式.它是MDI父级.在这个父母中,我打开第二个表格,然后使用一个类.
看起来像这样:
Hi,
i''ve got a main form. It''s an MDI Parent. In this parent i''m opening a second form and and i''m using a class.
Looks like this:
public partial class Main : Form
{
Serial serialPort = new Serial();
[...]
Util childForm = new Util();
[...]
childForm.Show();
这很好.我可以启动childForm并在主窗体中使用serialPort.
现在,我想在打开的childForm中使用我的Serial类中的方法.如果没有Main窗体中现有的serialPort,我该怎么办?
this works fine. I can start the childForm and work with the serialPort in my Main form.
Now i want to use the methodes from my Serial class in the opened childForm. How can i do this without the existing serialPort in the Main form?
推荐答案
您显然需要将对Serial类的引用传递给子窗体. :rolleyes:
创建一个重载的构造函数并传递它,或者创建一个属性并设置它.
You''ll need to pass a reference to the Serial class to the child form obviously. :rolleyes:
Create a overloaded constructor and pass it in or create a property and set it.
有可能,您给我一个例子,因为我找不到任何文章.我可以用错误的关键词搜索吗? :doh:
Is it possible, that you give me an example, cuz i can''t find any article. May i search with the wrong keywords. :doh:
这篇关于从第一种形式中以第二种形式调用甲基的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文