简体   繁体   中英

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). I want to display these Datasets in Windows.Forms each labeled, edit the values and send it back to the device. 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. I would like to design the layout in Form Designer, so not want to create the controls dynamically. 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). 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 .

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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