简体   繁体   English

WinForms:实现设置对话框?

[英]WinForms: Implement a settings dialog?

I have a Form with some data like name, favorite food or something, and want to be able to change these in a new form. 我有一个包含一些数据的表格,例如姓名,最喜欢的食物或其他东西,并且希望能够以新的形式进行更改。 This settings form should have the standard OK/Cancel/Apply buttons and update the main forms values on apply directly. 此设置表单应具有标准的“确定/取消/应用”按钮,并在直接应用时更新主要表单值。 What's the best way to do this? 最好的方法是什么? Thanks 谢谢

This will not cover the complete approach, but I'd recommend the PropertyGrid control for powerful and fast settings editing, but it might be not so user friendly so it depends what your target user group is. 这不会涵盖完整的方法,但是我建议您使用PropertyGrid控件进行功能强大且快速的设置编辑,但是它可能不那么用户友好,因此取决于您的目标用户组。 You can keep all your settings in a class with a public property for each setting. 您可以将所有设置保留在一个类中,并且每个设置都具有一个公共属性。 When setting the PropertyGrid s SelectedObject to an instance of this object you will be able to edit all settings directly. PropertyGridSelectedObject设置为此对象的实例时,您将能够直接编辑所有设置。 You can use some attributes to control the display of the properties. 您可以使用一些属性来控制属性的显示。

You can find a nice tutorial on using this Grid here . 您可以在此处找到有关使用此Grid的不错的教程。 Creating a basic Dialog Form with three buttons should be simple. 创建具有三个按钮的基本对话框表单应该很简单。 Hope that helps. 希望能有所帮助。

Create a class that will store the data. 创建一个将存储数据的类。 Show the data (perhaps using databinding in the first form and pass the same object to the edit form to initialize the controls in the edit form. 显示数据(也许在第一种形式中使用数据绑定,然后将同一对象传递给编辑形式以在编辑形式中初始化控件。

After closing the edit form with OK or Apply write the values of the controls to the data object. 单击“确定”或“应用”关闭编辑表单后,将控件的值写入数据对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM