using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); InitData(new byte[] { 0xC0, 0xAB, 0xCD }); } void InitData(byte[] rawData) { GCHandle handle = GCHandle.Alloc(rawData, GCHandleType.Pinned); Setting s = (Setting)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Setting)); checkBoxIsEnable.DataBindings.Add(new Binding("checked", s, "IsEnable")); comboBoxOption.DataBindings.Add(new Binding("SelectedIndex", s, "Option")); textBoxDecData.DataBindings.Add(new Binding("Text", s, "DecimalData")); textBoxHexData.DataBindings.Add(new Binding("Text", s, "HexData")); } } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct Setting { public byte control; public byte data1; public byte data2; public bool IsEnable { get { return (control & 0x80) == 0 ? false : true; } } public int Option { get { return (control & 0x60) >> 5; } } public int DecimalData { get { return data1; } } public string HexData { get { return data2.ToString("X02"); } } } }