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

}

}

}

相关推荐
FRing032 小时前
vue2干货总结12(loading效果、全局前置导航守卫、搜索历史管理)
开发语言·前端·javascript·vue.js·vue2
wefg12 小时前
【项目】C++ 基于 Vibe Coding 的 OJ 平台
开发语言·c++
琳少_5 小时前
java程序设计笔记
java·开发语言·数据库·笔记
Helix2507 小时前
JDK高频报错速查手册:javac不是内部命令、内存溢出、版本不兼容等12类问题解决方法
java·开发语言·内存溢出·java异常处理·jdk版本兼容·jdk报错·javac报错
郝学胜-神的一滴8 小时前
Effective STL 条款 07:指针容器销毁前先删除
开发语言·c++·vscode·leetcode·rpc·visual studio
CoderYanger8 小时前
A.每日一题:2243. 计算字符串的数字和
java·开发语言·程序人生·leetcode·面试·蓝桥杯·学习方法
摇滚侠10 小时前
《On Java 中文版 基础卷》阅读笔记 接口 19
java·开发语言·笔记
吃我一窝jio10 小时前
Java多线程核心知识点梳理
java·开发语言·笔记
geovindu12 小时前
rust: Timing Functions Pattern
开发语言·后端·设计模式·rust·计时函数模式·性能分析型模式
geovindu12 小时前
python:Lasso
开发语言·后端·python·算法