农场设备管理代码(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 });

}

}

}

相关推荐
佳得动几秒前
编译和链接的认识(C语言)
c语言·开发语言
大黄说说11 分钟前
PHP 异步怎么实现?Swoole、Workerman 使用场景对比
开发语言·php·swoole
十二同学啊11 分钟前
Python 工程化详解:项目结构、依赖管理、代码质量、测试与部署
java·开发语言·python
乐橙开放平台18 分钟前
跨地域监控难管理?通过 GB28181 把各地海康大华乐橙摄像头注册到云端平台
开发语言·笔记·物联网·自动化·php·音视频·智能家居
广东融科数据服务有限公司19 分钟前
网络监控经常卡顿、掉线、画面模糊?一线排查问答实录
开发语言·网络·php
Sarvartha40 分钟前
Iterator 迭代器、ListIterator & foreach 循环
开发语言
樱花落木兰44 分钟前
Redis 消息队列的可靠性演进:从 List、Pub/Sub 到 Stream 消费者组,以及 8.x 版本改变了什么
java·开发语言·经验分享·redis·分布式·python·软件工程
外收内放1 小时前
ENSP学习记录(6)
开发语言·学习·php
dialect_1 小时前
CODEFORCES ROUND 1127 DIV2
开发语言·c++·算法
盛世宏博北京1 小时前
档案库房恒温恒湿消毒净化一体机与3D可视化平台联动调试笔记
开发语言·php·温湿度·档案室