简体   繁体   English

打开新表格或编辑当前表格

[英]open new form or edit current form

I am starting a C# application for windows desktop machines. 我正在为Windows台式机启动C#应用程序。

I am wondering what the best method for my scenario would be. 我想知道我的方案的最佳方法是什么。

I have 2 simple forms, one will have a couple of buttons which will be the main start form. 我有2个简单的表单,其中一个将有几个按钮,它们将成为主要的开始表单。 The second form will have some labels and text fields that will be filled in with a scanner. 第二个表单将包含一些标签和文本字段,这些标签和文本字段将由扫描仪填写。 I will be trying later to accept entry only from the com port so whoever is using it doesnt have to select the program to have it get input. 稍后我将尝试仅接受来自com端口的输入,因此无论使用它的人都不必选择要输入的程序。 After the last textbox in the second form is filled right the program goes back to the first form. 在第二个表单中的最后一个文本框被填充后,程序将返回第一个表单。

I was thinking of showing the new form and hiding the main one but i was thinking it would be best in one window. 我当时想展示一种新的形式并隐藏主要形式,但我认为在一个窗口中最好。

I am very new to C# so this is learning experience for best practice. 我是C#的新手,因此这是最佳实践的学习经验。

Thank you 谢谢

I'm not very sure what king of information you want, but given "I am very new to C#", I'll give you information that I think I would have needed to know when I was "very new to C#". 我不确定您想要什么信息之王,但是鉴于“我对C#非常陌生”,我会给您一些信息,我想我什么时候应该对“ C#非常陌生”知道。

I'd personally recommend not using windows forms and going with WPF . 我个人建议不要使用Windows窗体,而应该使用WPF It allows you to make fully customizable applications and to add a lot of features (especially visual features) to your application that would not be possible using Forms . 它允许您制作完全可自定义的应用程序,并向您的应用程序添加很多功能(尤其是视觉功能),而使用Forms无法实现这些功能。

In the case of using WPF , you'd probably have one window, and two separate UserControls . 在使用WPF的情况下,您可能会有一个窗口和两个单独的UserControls Depending on how complicated this application might be, you should consider using a pattern like MVVM ( http://msdn.microsoft.com/en-us/magazine/dd419663.aspx ); 根据该应用程序的复杂程度,您应该考虑使用类似MVVM模式http://msdn.microsoft.com/zh-cn/magazine/dd419663.aspx ); the more complicated you might expect your application to get, the more I'd recommend using it. 您可能期望应用程序变得越复杂,我建议使用它就越多。

In the case of using MVVM , both of your Forms (I'll refer to them as UserControls ), would each have some DataContext set. 在使用MVVM的情况下,您的两个Forms (我将它们称为UserControls )都将设置一些DataContext The DataContext would be a class that the view (your UserControl ) would bind to. DataContext将是视图(您的UserControl )将绑定到的类。 So the idea is that you might have methods in this ViewModel (the DataContext ) that would fill its members with the data from the COM port, and the View (the UserControl ) would have bindings to its DataContext ( ViewModel ) that would indicate the data in the ViewModel . 因此,想法是,您可能在此ViewModelDataContext )中具有一些方法,该方法将用来自COM端口的数据填充其成员,而View( UserControl )将具有与其DataContextViewModel )的绑定,以指示数据在ViewModel The ViewModel would also have the responsibility of notifying the View when a value has been updated so it can show it. ViewModel还应负责在值更新时通知View,以便它可以显示它。 Properties on the ViewModel can also be updated(via bindings) to indicate that something has been changed by the user on the UserControl . 还可以(通过绑定)更新ViewModel上的属性,以指示用户已在UserControl上进行了更改。 So, for example, your Textbox might be bound to a String property , so that when the String property changes, the Textbox updates. 因此,例如,您的Textbox可能绑定到String property ,以便当String property更改时, Textbox更新。 Similarly, when the text in the Textbox changes, the string property would be updated. 同样,当“文本Textbox中的Textbox更改时,string属性将被更新。 This is all customizable. 这都是可定制的。 The idea is that there is a clean separation between the View and ViewModel so that stuff is easy to test and not as likely to break. 这个想法是在ViewViewModel之间有一个清晰的分隔,以便使内容易于测试并且不会损坏。

I'm not exactly sure what you're looking for, but I hope this helps!! 我不确定您要寻找的是什么,但是希望对您有所帮助!!

Good Luck 祝好运

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

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