public void setPacket() { IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(message)); Marshal.Copy(dataBytes, 0, ptr, Marshal.SizeOf(message)); message = (structMsgUdpT01)Marshal.PtrToStructure(ptr, message.GetType()); Marshal.FreeHGlobal(ptr); }
public void update(ListView lv, structMsgUdpT01 data) { foreach (var prop in data.GetType().GetProperties()) { ListViewItem lvi = lv.FindItemWithText(prop.Name); if (lvi != null) { lvi.SubItems[1].Text = string.Format("{0,8:0.00}", Convert.ToDouble(prop.GetValue(data, null).ToString())); } } }
public void init(ListView lv, structMsgUdpT01 data) { lv.DoubleBuffered(true); foreach (var prop in data.GetType().GetProperties()) { ListViewItem lvi = new ListViewItem(prop.Name); lvi.SubItems.Add(prop.GetValue(data, null).ToString()); lv.Items.Add(lvi); } }
public bool setData(ListView lv, ref structMsgUdpT01 message, double data) { object tempObj = message; foreach (var prop in tempObj.GetType().GetProperties()) { ListViewItem lvi = lv.FindItemWithText(prop.Name); if (lvi != null && lvi.Checked) { try { prop.SetValue(tempObj, Convert.ChangeType(data, prop.PropertyType), null); } catch { return(false); } } } message = (structMsgUdpT01)tempObj; return(true); }