C#实现仪表盘

2024-08-30 20:12
文章标签 c# 实现 仪表盘 .net netcore

本文主要是介绍C#实现仪表盘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、仪表盘控件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace DashboardApp
{[ToolboxBitmapAttribute(typeof(Dashboard), "Dashboard.bmp"),DefaultEvent("ValueInRangeChanged"),Description("Displays a value on an analog gauge. Raises an event if the value enters one of the definable ranges.")]public class Dashboard:Control{public Dashboard(){SetStyle(ControlStyles.OptimizedDoubleBuffer, true);}#region enum, var, delegate, eventpublic enum NeedleColorEnum{Gray = 0,Red = 1,Green = 2,Blue = 3,Yellow = 4,Violet = 5,Magenta = 6};private const Byte ZERO = 0;private const Byte NUMOFCAPS = 5;private const Byte NUMOFRANGES = 5;private Single fontBoundY1;private Single fontBoundY2;private Bitmap gaugeBitmap;private Boolean drawGaugeBackground = true;private Single m_value;private Boolean[] m_valueIsInRange = { false, false, false, false, false };private Byte m_CapIdx = 1;private Color[] m_CapColor = { Color.Black, Color.Black, Color.Black, Color.Black, Color.Black };private String[] m_CapText = { "", "", "", "", "" };private Point[] m_CapPosition = { new Point(10, 10), new Point(10, 10), new Point(10, 10), new Point(10, 10), new Point(10, 10) };private Point m_Center = new Point(100, 100);private Single m_MinValue = -100;private Single m_MaxValue = 400;private Color m_BaseArcColor = Color.Gray;private Int32 m_BaseArcRadius = 80;private Int32 m_BaseArcStart = 135;private Int32 m_BaseArcSweep = 270;private Int32 m_BaseArcWidth = 2;private Color m_ScaleLinesInterColor = Color.Black;private Int32 m_ScaleLinesInterInnerRadius = 73;private Int32 m_ScaleLinesInterOuterRadius = 80;private Int32 m_ScaleLinesInterWidth = 1;private Int32 m_ScaleLinesMinorNumOf = 9;private Color m_ScaleLinesMinorColor = Color.Gray;private Int32 m_ScaleLinesMinorInnerRadius = 75;private Int32 m_ScaleLinesMinorOuterRadius = 80;private Int32 m_ScaleLinesMinorWidth = 1;private Single m_ScaleLinesMajorStepValue = 50.0f;private Color m_ScaleLinesMajorColor = Color.Black;private Int32 m_ScaleLinesMajorInnerRadius = 70;private Int32 m_ScaleLinesMajorOuterRadius = 80;private Int32 m_ScaleLinesMajorWidth = 2;private Byte m_RangeIdx;private Boolean[] m_RangeEnabled = { true, true, false, false, false };private Color[] m_RangeColor = { Color.LightGreen, Color.Red, Color.FromKnownColor(KnownColor.Control), Color.FromKnownColor(KnownColor.Control), Color.FromKnownColor(KnownColor.Control) };private Single[] m_RangeStartValue = { -100.0f, 300.0f, 0.0f, 0.0f, 0.0f };private Single[] m_RangeEndValue = { 300.0f, 400.0f, 0.0f, 0.0f, 0.0f };private Int32[] m_RangeInnerRadius = { 70, 70, 70, 70, 70 };private Int32[] m_RangeOuterRadius = { 80, 80, 80, 80, 80 };private Int32 m_ScaleNumbersRadius = 95;private Color m_ScaleNumbersColor = Color.Black;private String m_ScaleNumbersFormat;private Int32 m_ScaleNumbersStartScaleLine;private Int32 m_ScaleNumbersStepScaleLines = 1;private Int32 m_ScaleNumbersRotation = 0;private Int32 m_NeedleType = 0;private Int32 m_NeedleRadius = 80;private NeedleColorEnum m_NeedleColor1 = NeedleColorEnum.Gray;private Color m_NeedleColor2 = Color.DimGray;private Int32 m_NeedleWidth = 2;public class ValueInRangeChangedEventArgs : EventArgs{public Int32 valueInRange;public ValueInRangeChangedEventArgs(Int32 valueInRange){this.valueInRange = valueInRange;}}public delegate void ValueInRangeChangedDelegate(Object sender, ValueInRangeChangedEventArgs e);[Description("This event is raised if the value falls into a defined range.")]public event ValueInRangeChangedDelegate ValueInRangeChanged;#endregion#region hidden , overridden inherited propertiespublic new Boolean AllowDrop{get{return false;}set{}}public new Boolean AutoSize{get{return false;}set{}}public new Boolean ForeColor{get{return false;}set{}}public new Boolean ImeMode{get{return false;}set{}}public override System.Drawing.Color BackColor{get{return base.BackColor;}set{base.BackColor = value;drawGaugeBackground = true;Refresh();}}public override System.Drawing.Font Font{get{return base.Font;}set{base.Font = value;drawGaugeBackground = true;Refresh();}}public override System.Windows.Forms.ImageLayout BackgroundImageLayout{get{return base.BackgroundImageLayout;}set{base.BackgroundImageLayout = value;drawGaugeBackground = true;Refresh();}}#endregion#region properties[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.Description("The value.")]public Single Value{get{return m_value;}set{if (m_value != value){m_value = Math.Min(Math.Max(value, m_MinValue), m_MaxValue);if (this.DesignMode){drawGaugeBackground = true;}for (Int32 counter = 0; counter < NUMOFRANGES - 1; counter++){if ((m_RangeStartValue[counter] <= m_value)&& (m_value <= m_RangeEndValue[counter])&& (m_RangeEnabled[counter])){if (!m_valueIsInRange[counter]){if (ValueInRangeChanged != null){ValueInRangeChanged(this, new ValueInRangeChangedEventArgs(counter));}}}else{m_valueIsInRange[counter] = false;}}Refresh();}}}[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.RefreshProperties(RefreshProperties.All),System.ComponentModel.Description("The caption index. set this to a value of 0 up to 4 to change the corresponding caption's properties.")]public Byte Cap_Idx{get{return m_CapIdx;}set{if ((m_CapIdx != value)&& (0 <= value)&& (value < 5)){m_CapIdx = value;}}}[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.Description("The color of the caption text.")]private Color CapColor{get{return m_CapColor[m_CapIdx];}set{if (m_CapColor[m_CapIdx] != value){m_CapColor[m_CapIdx] = value;CapColors = m_CapColor;drawGaugeBackground = true;Refresh();}}}[System.ComponentModel.Browsable(false)]public Color[] CapColors{get{return m_CapColor;}set{m_CapColor = value;}}[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.Description("The text of the caption.")]public String CapText{get{return m_CapText[m_CapIdx];}set{if (m_CapText[m_CapIdx] != value){m_CapText[m_CapIdx] = value;CapsText = m_CapText;drawGaugeBackground = true;Refresh();}}}[System.ComponentModel.Browsable(false)]public String[] CapsText{get{return m_CapText;}set{for (Int32 counter = 0; counter < 5; counter++){m_CapText[counter] = value[counter];}}}[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.Description("The position of the caption.")]public Point CapPosition{get{return m_CapPosition[m_CapIdx];}set{if (m_CapPosition[m_CapIdx] != value){m_CapPosition[m_CapIdx] = value;CapsPosition = m_CapPosition;drawGaugeBackground = true;Refresh();}}}[System.ComponentModel.Browsable(false)]public Point[] CapsPosition{get{return m_CapPosition;}set{m_CapPosition = value;}}[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.Description("The center of the gauge (in the control's client area).")]public Point Center{get{return m_Center;}set{if (m_Center != value){m_Center = value;drawGaugeBackground = true;Refresh();}}}[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.Description("The minimum value to show on the scale.")]public Single MinValue{get{return m_MinValue;}set{if ((m_MinValue != value)&& (value < m_MaxValue)){m_MinValue = value;drawGaugeBackground = true;Refresh();}}}[System.ComponentModel.Browsable(true),System.ComponentModel.Category("AGauge"),System.ComponentModel.Description("The maximum value to show on the scale.")]public Single MaxValue{get{return m_MaxValue;}set{if ((m_MaxValue != value)&& (value > m_MinValue)){m_MaxValue = value;drawGaugeBackground = true;Refresh();}}}[System.ComponentModel.Browsable

这篇关于C#实现仪表盘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1121817

相关文章

AJAX请求上传下载进度监控实现方式

《AJAX请求上传下载进度监控实现方式》在日常Web开发中,AJAX(AsynchronousJavaScriptandXML)被广泛用于异步请求数据,而无需刷新整个页面,:本文主要介绍AJAX请... 目录1. 前言2. 基于XMLHttpRequest的进度监控2.1 基础版文件上传监控2.2 增强版多

Redis分片集群的实现

《Redis分片集群的实现》Redis分片集群是一种将Redis数据库分散到多个节点上的方式,以提供更高的性能和可伸缩性,本文主要介绍了Redis分片集群的实现,具有一定的参考价值,感兴趣的可以了解一... 目录1. Redis Cluster的核心概念哈希槽(Hash Slots)主从复制与故障转移2.

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

Mybatis 传参与排序模糊查询功能实现

《Mybatis传参与排序模糊查询功能实现》:本文主要介绍Mybatis传参与排序模糊查询功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、#{ }和${ }传参的区别二、排序三、like查询四、数据库连接池五、mysql 开发企业规范一、#{ }和${ }传参的

Docker镜像修改hosts及dockerfile修改hosts文件的实现方式

《Docker镜像修改hosts及dockerfile修改hosts文件的实现方式》:本文主要介绍Docker镜像修改hosts及dockerfile修改hosts文件的实现方式,具有很好的参考价... 目录docker镜像修改hosts及dockerfile修改hosts文件准备 dockerfile 文

基于SpringBoot+Mybatis实现Mysql分表

《基于SpringBoot+Mybatis实现Mysql分表》这篇文章主要为大家详细介绍了基于SpringBoot+Mybatis实现Mysql分表的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录基本思路定义注解创建ThreadLocal创建拦截器业务处理基本思路1.根据创建时间字段按年进

SpringBoot3实现Gzip压缩优化的技术指南

《SpringBoot3实现Gzip压缩优化的技术指南》随着Web应用的用户量和数据量增加,网络带宽和页面加载速度逐渐成为瓶颈,为了减少数据传输量,提高用户体验,我们可以使用Gzip压缩HTTP响应,... 目录1、简述2、配置2.1 添加依赖2.2 配置 Gzip 压缩3、服务端应用4、前端应用4.1 N

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整