English 中文(简体)
添加“视窗形式”的方法
原标题:Adding Methods To Windows Form?
  • 时间:2011-05-01 06:53:31
  •  标签:
  • c#

我有2个窗口表格,一个是父母,另一个是儿童。 父母是主要形式。 孩子们是一位方言,使用者可以 where弄他们的细节。

如果在母体表格上点击,则装上儿童表格。 与此类似:

private void add_account_Click(object sender, EventArgs e)
{
     this.account_add_edit = new Form2();
     account_add_edit.test();
     account_add_edit.ShowDialog();
}

As you can see I ve created a new form, tried to call a function from the new form, and then showed the form. The problem is the method from the form is not being called. I am getting an error on the IDE that says Windows.Forms.Form does not contain a method test.

I ve created the method in the child form:

public static string test(string val)
{
    this.username = val;
}

任何关于我做什么错误的想法?

问题回答

your method is defined as static , so its not posiible to call it on an instace. you should eaither not make it static, or call it from as static:

Form2.test();

Use:

   Form2.test();

<代码>static members are direct associated to the class not to its instances/em>。 您需要查阅<代码>static 成员必须使用该集装箱类型<>。

More than that, you can not access normal members from static ones. You can only access staticmembers from their peers.

You cannot do the following inside a static method:

this.Member ...




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...