农场设备管理代码(2)

using Dias_Interface;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace Dias_Farm

{

public partial class UC_Device_Data : UserControl

{

Dias_Interface.DeviceInfo DEV = null;

Timer t = new Timer() { Interval = 1000,Enabled=false };

public Dias_Interface.DeviceInfo Device

{

get { return DEV; }

set

{

if (value != null && value != DEV) DEV = value;

}

}

public bool IsRuning

{

get

{

return t.Enabled;

}

set

{

t.Enabled = value;

}

}

public UC_Device_Data()

{

InitializeComponent();

this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);

this.Paint += UC_Device_Data_Paint;

t.Tick += (sender, e) =>

{

this.Refresh();

};

this.Disposed += (sender, e) =>

{

t.Enabled = false;

t.Dispose();

GC.Collect();

};

this.MouseClick += (sender, e) =>

{

OnDeviceClick?.Invoke(this, new Point(e.X, e.Y), 0);

};

this.MouseDoubleClick += (sender, e) =>

{

OnDeviceClick?.Invoke(this, new Point(e.X, e.Y), 1);

};

}

public event Action<UC_Device_Data,Point, int> OnDeviceClick;

private void UC_Device_Data_Paint(object sender, PaintEventArgs e)

{

if (DEV == null)

{

e.Graphics.DrawString($"农场设备", this.Font, new SolidBrush(this.ForeColor),

new Rectangle(Point.Empty, this.ClientSize),

new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });

return;

}

Graphics g=e.Graphics;

switch (DEV.Type)

{

case Dias_Interface.DeviceType.Data:

{

DrawDataControls(g,DEV);

}

break;

case DeviceType.Control:

{

DrawControlControls(g,DEV);

}

break;

case DeviceType.Monitor:

{

DrawMonitorControls(g,DEV);

}

break;

default:

{

break;

}

}

}

private void DrawMonitorControls(Graphics g, IDEVICE e)

{

Image img = null;

try

{

img = Image.FromStream(new MemoryStream(e.ByteValue));

}

catch { img = null; }

if (img != null)

{

g.DrawImage(img, new Rectangle(Point.Empty, this.ClientSize),new Rectangle(Point.Empty,img.Size),GraphicsUnit.Pixel);

img.Dispose();

img = null;

}

}

private void DrawControlControls(Graphics g, IDEVICE e)

{

g.DrawString($"{e.Name}【{(e.Value>=1?"开":"关")}】", this.Font, new SolidBrush(this.ForeColor), new Rectangle(Point.Empty, this.ClientSize),

new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });

}

private void DrawDataControls(Graphics g, IDEVICE e)

{

g.DrawString($"{e.Name}【{e.Value.ToString("0.00")}】{e.Set.Get<string>("Unit")}", this.Font, new SolidBrush(this.ForeColor), new Rectangle(Point.Empty, this.ClientSize),

new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });

}

}

}

相关推荐
门思科技6 分钟前
LoRaWAN 设备类别:Class A、B、C 对比与选型指南
c语言·开发语言·php
恋恋西风3 小时前
C++ 理解 std::thread 在单核和多核上的行为差异
开发语言·c++
Brilliantwxx3 小时前
【Linux】 进程(9)程序与进程地址空间(基础+进阶+面试题)
linux·运维·服务器·开发语言·c++
BizzZ_3 小时前
C++(22)——类型转换和IO流
开发语言·c++
小范同学_4 小时前
JDK1.7 与 JDK1.8 HashMap 底层原理对比 + 数组并发扩容死循环详解
java·开发语言
geovindu4 小时前
CSharp: 万年历
开发语言·后端·c#·.net
我找到地球的支点啦4 小时前
Matlab系列(009) 一CRC循环冗余校验详解
开发语言·数据结构·算法·matlab·信息与通信
予昊4 小时前
从零实现“在线五子棋对战“:WebSocket 实时通信 + 段位匹配
java·开发语言·网络·websocket
weixin_461408585 小时前
Mybatis-flex小记
java·开发语言·mybatis
青梅味猪大肠6 小时前
【深入浅出C++】为什么虚表指针可以解决菱形继承
开发语言·c++