如何从父表单继承子表单 [英] How to inherit a child form from the parent form

查看:83
本文介绍了如何从父表单继承子表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我有多种形式.数据互不相同.有些功能是所有表格共有的.我想要的是制作一个父窗体并将通用代码放置在那里.请帮助我如何为所有表格创建共同的父母.
感谢您阅读我的问题.

Hi friends,
I have a number of forms. There data are different from each other. There are some functions that are common to all the forms. What I want is to make a parent form and place the common code there. Please help me how can I create a common parent for all the forms.
thank you for reading my question.

推荐答案

创建一个新的类,如下所示:

Create a new class like this:

public partial class FormBase : Form
{
  // put your common data members/methods in here
}

然后,您可以继承其他所有形式的表单,如下所示:

Then, you can inherit this form in all of your other forms, like this:

public partial class MyForm1 : FormBase
{
}



确保为每个对象都提供一个默认的构造函数,以便您仍可以在设计器中使用它们.

编辑=========

为什么我的答案被选为1?完全没有任何意义.



Make sure you give each one a default constructor so you can still work with them in the designer.

EDIT =========

Why was my answer voted a 1? That makes no sense at all.


首先创建一个名称为Parent的表单,标识符应为Public:
First Create a form name it Parent, identifier should be Public:
public partial class Parent : Form
{
 // You can have Protected variables and Methods
}



现在您可以将子表单名称命名为child



Now you can make child form name child

public partial class child : Parent
{
 // you can use all protected variables and methods of Parent class
}


此处 [ ^ ]是Microsoft所谓的视觉继承的演练.

看看是否有帮助.
Here[^] is a Walkthrough of what Microsoft call Visual Inheritance.

See if that helps.


这篇关于如何从父表单继承子表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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