简体   繁体   English

C# Windows Forms

[英]C# Windows Forms

I am new here and startig to learn C#. Before I programed in C and Windows.Forms in VBA. Now I have a Project where I receive serial port data from a device, that sends the contents of various C-structs (some nested).我是新来的,开始学习 C#。之前我在 C 和 VBA 中编程 Windows.Forms。现在我有一个项目,我从设备接收串行端口数据,发送各种 C 结构(一些嵌套)的内容。 I want to display these Datasets in Windows.Forms each labeled, edit the values and send it back to the device.我想在 Windows.Forms 中显示这些数据集,每个都标记,编辑值并将其发送回设备。 So it can easily copy the received data into its structures.所以它可以轻松地将接收到的数据复制到它的结构中。 Now I don't know an easy way to get the structured data inside ac#-byte-list into various text boxes(?) that have describing labels to it.现在我不知道有什么简单的方法可以将 ac#-byte-list 中的结构化数据放入具有描述标签的各种文本框(?)中。 I would like to design the layout in Form Designer, so not want to create the controls dynamically.我想在 Form Designer 中设计布局,所以不想动态创建控件。 But maybe this is the best way?但也许这是最好的方法? Does someone know a good strategy / a best suited control to achieve this?有人知道实现此目标的好策略/最适合的控件吗? Thanks in advance.提前致谢。

You could use a DataGridView with control buttons inside each row or external buttons that handle selected row(s).您可以使用每行内带有控制按钮的DataGridView或处理选定行的外部按钮。 In order to see and change the details a corresponding dialog form comes in handy in which I would implement a hex editor with the byte/hex values on the left and the readable value on the right.为了查看和更改详细信息,相应的对话框形式会派上用场,我将在其中实现一个十六进制编辑器,左侧是字节/十六进制值,右侧是可读值。

To display the byte data just convert it to a hexadecimal string so you can display it in one column inside the DataGridView .要显示字节数据,只需将其转换为十六进制字符串,以便您可以将其显示在DataGridView内的一列中。

For the nesting part, you could either implement child elements inside the DataGridView itself (you need to either code this yourself or use some 3rd party extensions like this or Telerik , eg, which also has the possibility of including button columns ) or open a conditional dialog form which again shows a DataGridView for the child elements and so on (so you would open the same form as child form ad infinitum).对于嵌套部分,您可以在DataGridView本身内部实现子元素(您需要自己编写代码或使用像这样的第三方扩展或Telerik ,例如,它也有可能包含按钮列)或打开条件再次显示子元素的 DataGridView 的对话框窗体等等(因此您将无限地打开与子窗体相同的窗体)。

Thereby you are as flexible as possible and do not rely on fixed text box elements which you have to add or extend on further information.因此,您尽可能灵活,不依赖于必须添加或扩展更多信息的固定文本框元素。

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

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