using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.Common; using IntelligentControlForsx.Model; using IntelligentControlForsx.Service; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; namespace IntelligentControlForsx.MyControls { public partial class WDevice : UserControl { public WDevice() { InitializeComponent(); } string deviceId; string deviceModel; string stationId; double status; [Browsable(true), Category("Data")] public double Status { get { return status; } set { status = value; this.BackColor = getBackColor(value); } } private CmdType cType; public CmdType CType { set { cType = value; } get { return cType; } } [Browsable(true), Category("Data")] public string DeviceId { get { return deviceId; } set { deviceId = value; lblDeviceId.Text = value; } } public string DeviceModel { get { return deviceModel; } set { deviceModel = value; } } public string StationId { get { return stationId; } set { stationId = value; } } private Color getBackColor(double status) { int st = Convert.ToInt32(status); switch (st) { //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS case 0: //停机状态 return Color.FromArgb(176, 151, 63); case 1: //上电状态 return Color.FromArgb(177, 14, 126); case 2: //待机状态 return Color.FromArgb(15, 141, 106); case 3: //启动状态 return Color.FromArgb(14, 72, 91); case 4: //并网状态 return Color.FromArgb(15, 135, 170); case 5: //故障状态 return Color.FromArgb(170, 15, 59); case 6: //维护状态 return Color.FromArgb(204, 83, 51); case 7: //离线状态 return Color.FromArgb(134, 150, 165); default: return Color.Black; } } private Rectangle dragBoxFromMouseDown; private void lblDeviceId_MouseDown(object sender, MouseEventArgs e) { //记录鼠标按下位置,DragSize获取以鼠标按钮的按下点为中心的矩形的宽度和高度,在该矩形内不会开始拖动操作。 Size dragSize = SystemInformation.DragSize; //创建一个矩形区域(正方形)。以鼠标按下电为中心,以DragSize为高和宽的矩形。 dragBoxFromMouseDown = new Rectangle(new System.Drawing.Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize); } private void lblDeviceId_MouseMove(object sender, MouseEventArgs e) { //如果鼠标位置在拖动矩形之外(就可以开始拖动了) if (dragBoxFromMouseDown != Rectangle.Empty && !dragBoxFromMouseDown.Contains(e.X, e.Y)) { //传递ListBox选中项并触发DoDragDrop事件(这里可以是ListDragSoure触发,也可以是ListDragTarget) //DoDragDrop 方法确定当前光标位置下的控件。然后它将检查该控件是否是有效的放置目标。 DragDropEffects dropEffect = this.DoDragDrop(this.deviceId, DragDropEffects.All | DragDropEffects.Link); //if (dropEffect == DragDropEffects.Move) //{ //} } } //protected override void WndProc(ref Message m) //{ // if (m.Msg == 0x0014) // 禁掉清除背景消息 // return; // base.WndProc(ref m); //} protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } public bool isSelect; public bool IsSelect { set { if (isSelect) { isSelect = false; if (MatrixPanel.lblList.Contains(this.DeviceId)) MatrixPanel.lblList.Remove(this.DeviceId); } else { isSelect = true; if (MatrixPanel.lblList.Contains(this.DeviceId) == false) MatrixPanel.lblList.Add(this.DeviceId); } if (isSelect) { lblDeviceId.ForeColor = Color.Black; lblDeviceId.BackColor = Color.White; } else { lblDeviceId.ForeColor = Color.White; lblDeviceId.BackColor = Color.Transparent; } } get { return isSelect; } } private void lblDeviceId_Click(object sender, EventArgs e) { this.IsSelect = true; } public event EventHandler MyMouseDown; public event EventHandler MyMouseUp; private void WDevice_Click(object sender, EventArgs e) { this.IsSelect = true; } } }