The majority of my forms for my project include an OK and Cancel button. (always positioned at the bottom right of the form). Currently I have a base class that inherits from System.Windows.Forms which contains an OK and Cancel button. All forms that use this then inherit from this base form class. Is there a better way of doing this that takes localization into consideration?
我项目的大多数表单都包含“确定”和“取消”按钮。 (始终位于表单的右下角)。目前我有一个继承自System.Windows.Forms的基类,它包含一个OK和Cancel按钮。然后,使用它的所有表单都从此基本表单类继承。是否有更好的方法来考虑本地化?
3 个解决方案
#1
1
I would use MDI Child Forms for this. Parent Form Can contain OK/Cancel button where as you would have your child form in MDI container.
我会使用MDI子表单。父表单可以包含“确定/取消”按钮,就像在MDI容器中使用子表单一样。
For More help visit https://msdn.microsoft.com/en-us/library/aa984329(v=vs.71).aspx
如需更多帮助,请访问https://msdn.microsoft.com/en-us/library/aa984329(v=vs.71).aspx
#2
1
You could just create a single form that has an empty panel or table layout, where you dynamically load the desired user control. It is basically the composition over inheritance principle.
您可以创建一个具有空面板或表格布局的单个表单,您可以在其中动态加载所需的用户控件。它基本上是继承原则的构成。
public partial class MyFormWithButtons : Form
{
public MyFormWithButtons(UserControl control)
{
InitializeComponent();
control.Dock = DockStyle.Fill;
myPanel.Controls.Add(control);
}
}
#3
1
Doing form inheritance is very useful in many levels:
在许多层面上进行表单继承非常有用:
- Make a base form, and name it for ex: FrmBase.
- 创建一个基本表单,并为ex:FrmBase命名。
- Add the Ok, Cancel Buttons to it and set the Anchor property for both to Bottom.
- 添加“确定”,“取消按钮”并将两者的“锚点”属性设置为“底部”。
- Set the Buttons "Modifiers" property to "Internal", this way you can access these buttons from inherited forms:
- 将按钮“Modifiers”属性设置为“Internal”,这样您就可以从继承的表单中访问这些按钮:
- Make as many forms as you want and make each inherit from the FrmBase ex: Form1 : FrmBase
- 制作任意数量的表单,并使每个继承自FrmBase ex:Form1:FrmBase
- now you can access the buttons from this from, using the properties.
- 现在,您可以使用属性从中访问这些按钮。
Hope this being useful for you.
希望这对你有用。
#1
1
I would use MDI Child Forms for this. Parent Form Can contain OK/Cancel button where as you would have your child form in MDI container.
我会使用MDI子表单。父表单可以包含“确定/取消”按钮,就像在MDI容器中使用子表单一样。
For More help visit https://msdn.microsoft.com/en-us/library/aa984329(v=vs.71).aspx
如需更多帮助,请访问https://msdn.microsoft.com/en-us/library/aa984329(v=vs.71).aspx
#2
1
You could just create a single form that has an empty panel or table layout, where you dynamically load the desired user control. It is basically the composition over inheritance principle.
您可以创建一个具有空面板或表格布局的单个表单,您可以在其中动态加载所需的用户控件。它基本上是继承原则的构成。
public partial class MyFormWithButtons : Form
{
public MyFormWithButtons(UserControl control)
{
InitializeComponent();
control.Dock = DockStyle.Fill;
myPanel.Controls.Add(control);
}
}
#3
1
Doing form inheritance is very useful in many levels:
在许多层面上进行表单继承非常有用:
- Make a base form, and name it for ex: FrmBase.
- 创建一个基本表单,并为ex:FrmBase命名。
- Add the Ok, Cancel Buttons to it and set the Anchor property for both to Bottom.
- 添加“确定”,“取消按钮”并将两者的“锚点”属性设置为“底部”。
- Set the Buttons "Modifiers" property to "Internal", this way you can access these buttons from inherited forms:
- 将按钮“Modifiers”属性设置为“Internal”,这样您就可以从继承的表单中访问这些按钮:
- Make as many forms as you want and make each inherit from the FrmBase ex: Form1 : FrmBase
- 制作任意数量的表单,并使每个继承自FrmBase ex:Form1:FrmBase
- now you can access the buttons from this from, using the properties.
- 现在,您可以使用属性从中访问这些按钮。
Hope this being useful for you.
希望这对你有用。