继承,如何为一个类赋予一个函数,然后许多其他人在它们的定义中都有它。 [英] Inheritance, how to give a function to a class, then many other have it in their definition.

查看:57
本文介绍了继承,如何为一个类赋予一个函数,然后许多其他人在它们的定义中都有它。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



提前感谢花时间阅读这个问题并帮助我。



假设我有一个程序10个窗口形式。现在我希望他们都有一个特定的独特功能,我不想重写它10次,我想将该功能放在一个类中,然后其他类可以在它们的实现中具有该功能。



我尝试了什么:



目前我正在寻找它,但我我不知道它。

Hi,
In advance thanks for spending time for reading this question and helping me.

Let's say I have a program with 10 windows forms. now I want them all to have a specific unique function, I don't want to rewrite it 10 times, I'd like to put the function in a class and then other classes can have that function in their implementation.

What I have tried:

Currently I'm searching for it and yet I have no idea about it.

推荐答案

如果基于Form创建一个新类的最简单方法:

The easiest way if to create a new class based on Form:
public class MyForm : Form
   {
   ...
   public string MethodAvailableInAllDerivedClasses(string parameter)
      {
      ...
      }
   ...
   }

然后将所有真实表单改为派生而来直接来自Form。

And then change all your "real" forms to derive from that instead of directly from Form.


这篇关于继承,如何为一个类赋予一个函数,然后许多其他人在它们的定义中都有它。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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