這篇文章主要介紹c#中Winform自定義控件如何實(shí)現(xiàn)儀表盤功能,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)建站專注于陳倉(cāng)企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),電子商務(wù)商城網(wǎng)站建設(shè)。陳倉(cāng)網(wǎng)站建設(shè)公司,為陳倉(cāng)等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)
準(zhǔn)備工作
依然使用GDI+畫的,不懂的話就百度一下吧
另外主要用到了三角函數(shù),如果不懂,可以向初中的數(shù)學(xué)老師再問(wèn)問(wèn)(你也可以百度一下)
開始
添加一個(gè)類UCMeter 繼承 UserControl
首先添加一個(gè)需要控制的屬性
private int splitCount = 10; ////// Gets or sets the split count. /// ///The split count. [Description("分隔刻度數(shù)量,>1"), Category("自定義")] public int SplitCount { get { return splitCount; } set { if (value < 1) return; splitCount = value; Refresh(); } } private int meterDegrees = 150; ////// Gets or sets the meter degrees. /// ///The meter degrees. [Description("表盤跨度角度,0-360"), Category("自定義")] public int MeterDegrees { get { return meterDegrees; } set { if (value > 360 || value <= 0) return; meterDegrees = value; Refresh(); } } private decimal minValue = 0; ////// Gets or sets the minimum value. /// ///The minimum value. [Description("最小值,= maxValue) return; minValue = value; Refresh(); } } private decimal maxValue = 100; /// /// Gets or sets the maximum value. /// ///The maximum value. [Description("最大值,>MinValue"), Category("自定義")] public decimal MaxValue { get { return maxValue; } set { if (value <= minValue) return; maxValue = value; Refresh(); } } ////// 獲取或設(shè)置控件顯示的文字的字體。 /// ///The font. ////// [Description("刻度字體"), Category("自定義")] public override Font Font { get { return base.Font; } set { base.Font = value; Refresh(); } } private decimal m_value = 0; ////// /// /// /// /// Gets or sets the value. /// ///The value. [Description("值,>=MinValue并且<=MaxValue"), Category("自定義")] public decimal Value { get { return m_value; } set { if (value < minValue || value > maxValue) return; m_value = value; Refresh(); } } private MeterTextLocation textLocation = MeterTextLocation.None; ////// Gets or sets the text location. /// ///The text location. [Description("值和固定文字顯示位置"), Category("自定義")] public MeterTextLocation TextLocation { get { return textLocation; } set { textLocation = value; Refresh(); } } private string fixedText; ////// Gets or sets the fixed text. /// ///The fixed text. [Description("固定文字"), Category("自定義")] public string FixedText { get { return fixedText; } set { fixedText = value; Refresh(); } } private Font textFont = DefaultFont; ////// Gets or sets the text font. /// ///The text font. [Description("值和固定文字字體"), Category("自定義")] public Font TextFont { get { return textFont; } set { textFont = value; Refresh(); } } private Color externalRoundColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the external round. /// ///The color of the external round. [Description("外圓顏色"), Category("自定義")] public Color ExternalRoundColor { get { return externalRoundColor; } set { externalRoundColor = value; Refresh(); } } private Color insideRoundColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the inside round. /// ///The color of the inside round. [Description("內(nèi)圓顏色"), Category("自定義")] public Color InsideRoundColor { get { return insideRoundColor; } set { insideRoundColor = value; Refresh(); } } private Color boundaryLineColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the boundary line. /// ///The color of the boundary line. [Description("邊界線顏色"), Category("自定義")] public Color BoundaryLineColor { get { return boundaryLineColor; } set { boundaryLineColor = value; Refresh(); } } private Color scaleColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the scale. /// ///The color of the scale. [Description("刻度顏色"), Category("自定義")] public Color ScaleColor { get { return scaleColor; } set { scaleColor = value; Refresh(); } } private Color scaleValueColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the scale value. /// ///The color of the scale value. [Description("刻度值文字顏色"), Category("自定義")] public Color ScaleValueColor { get { return scaleValueColor; } set { scaleValueColor = value; Refresh(); } } private Color pointerColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the pointer. /// ///The color of the pointer. [Description("指針顏色"), Category("自定義")] public Color PointerColor { get { return pointerColor; } set { pointerColor = value; Refresh(); } } private Color textColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the text. /// ///The color of the text. [Description("值和固定文字顏色"), Category("自定義")] public Color TextColor { get { return textColor; } set { textColor = value; Refresh(); } } Rectangle m_rectWorking;
重繪
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); var g = e.Graphics; g.SetGDIHigh(); //外圓 float fltStartAngle = -90 - (meterDegrees) / 2 + 360; var r1 = new Rectangle(m_rectWorking.Location, new Size(m_rectWorking.Width, m_rectWorking.Width)); g.DrawArc(new Pen(new SolidBrush(externalRoundColor), 1), r1, fltStartAngle, meterDegrees); //內(nèi)圓 var r2 = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Top + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Width / 4, m_rectWorking.Width / 4); g.DrawArc(new Pen(new SolidBrush(insideRoundColor), 1), r2, fltStartAngle, meterDegrees); //邊界線 if (meterDegrees != 360) { float fltAngle = fltStartAngle - 180; float intY = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float intX = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Cos(Math.PI * (fltAngle / 180.00F))))); g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(intX, intY), new PointF(fltX1, fltY1)); g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(m_rectWorking.Right - (fltX1 - m_rectWorking.Left), fltY1), new PointF(m_rectWorking.Right - (intX - m_rectWorking.Left), intY)); } //分割線 int _splitCount = splitCount * 2; float fltSplitValue = (float)meterDegrees / (float)_splitCount; for (int i = 0; i <= _splitCount; i++) { float fltAngle = (fltStartAngle + fltSplitValue * i - 180) % 360; float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); float fltY2 = 0; float fltX2 = 0; if (i % 2 == 0) { fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); if (!(meterDegrees == 360 && i == _splitCount)) { decimal decValue = minValue + (maxValue - minValue) / _splitCount * i; var txtSize = g.MeasureString(decValue.ToString("0.##"), this.Font); float fltFY1 = (float)(m_rectWorking.Top - txtSize.Height / 2 + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float fltFX1 = (float)(m_rectWorking.Left - txtSize.Width / 2 + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); g.DrawString(decValue.ToString("0.##"), Font, new SolidBrush(scaleValueColor), fltFX1, fltFY1); } } else { fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); } g.DrawLine(new Pen(new SolidBrush(scaleColor), i % 2 == 0 ? 2 : 1), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2)); } //值文字和固定文字 if (textLocation != MeterTextLocation.None) { string str = m_value.ToString("0.##"); var txtSize = g.MeasureString(str, textFont); float fltY = m_rectWorking.Top + m_rectWorking.Width / 4 - txtSize.Height / 2; float fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2; g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY)); if (!string.IsNullOrEmpty(fixedText)) { str = fixedText; txtSize = g.MeasureString(str, textFont); fltY = m_rectWorking.Top + m_rectWorking.Width / 4 + txtSize.Height / 2; fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2; g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY)); } } //畫指針 g.FillEllipse(new SolidBrush(Color.FromArgb(100, pointerColor.R, pointerColor.G, pointerColor.B)), new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 10, m_rectWorking.Top + m_rectWorking.Width / 2 - 10, 20, 20)); g.FillEllipse(Brushes.Red, new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 5, m_rectWorking.Top + m_rectWorking.Width / 2 - 5, 10, 10)); float fltValueAngle = (fltStartAngle + ((float)(m_value - minValue) / (float)(maxValue - minValue)) * (float)meterDegrees - 180) % 360; float intValueY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Sin(Math.PI * (fltValueAngle / 180.00F)))); float intValueX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Cos(Math.PI * (fltValueAngle / 180.00F))))); g.DrawLine(new Pen(new SolidBrush(pointerColor), 3), intValueX1, intValueY1, m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + m_rectWorking.Width / 2); }
還有一個(gè)顯示文字位置的枚舉
////// Enum MeterTextLocation /// public enum MeterTextLocation { ////// The none /// None, ////// The top /// Top, ////// The bottom /// Bottom }
代碼就這么多了,看完整代碼
// ***********************************************************************// Assembly : HZH_Controls// Created : 2019-09-03//// ***********************************************************************//// Copyright by Huang Zhenghui(黃正輝) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com// //// Blog: https://www.cnblogs.com/bfyx// GitHub:https://github.com/kwwwvagaa/NetWinformControl// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git//// If you use this code, please keep this note.// ***********************************************************************using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing;using System.Drawing.Drawing2D;using System.ComponentModel;namespace HZH_Controls.Controls{ ////// Class UCMeter. /// Implements the ////// public class UCMeter : UserControl { private int splitCount = 10; /// /// Gets or sets the split count. /// ///The split count. [Description("分隔刻度數(shù)量,>1"), Category("自定義")] public int SplitCount { get { return splitCount; } set { if (value < 1) return; splitCount = value; Refresh(); } } private int meterDegrees = 150; ////// Gets or sets the meter degrees. /// ///The meter degrees. [Description("表盤跨度角度,0-360"), Category("自定義")] public int MeterDegrees { get { return meterDegrees; } set { if (value > 360 || value <= 0) return; meterDegrees = value; Refresh(); } } private decimal minValue = 0; ////// Gets or sets the minimum value. /// ///The minimum value. [Description("最小值,= maxValue) return; minValue = value; Refresh(); } } private decimal maxValue = 100; /// /// Gets or sets the maximum value. /// ///The maximum value. [Description("最大值,>MinValue"), Category("自定義")] public decimal MaxValue { get { return maxValue; } set { if (value <= minValue) return; maxValue = value; Refresh(); } } ////// 獲取或設(shè)置控件顯示的文字的字體。 /// ///The font. ////// [Description("刻度字體"), Category("自定義")] public override Font Font { get { return base.Font; } set { base.Font = value; Refresh(); } } private decimal m_value = 0; ////// /// /// /// /// Gets or sets the value. /// ///The value. [Description("值,>=MinValue并且<=MaxValue"), Category("自定義")] public decimal Value { get { return m_value; } set { if (value < minValue || value > maxValue) return; m_value = value; Refresh(); } } private MeterTextLocation textLocation = MeterTextLocation.None; ////// Gets or sets the text location. /// ///The text location. [Description("值和固定文字顯示位置"), Category("自定義")] public MeterTextLocation TextLocation { get { return textLocation; } set { textLocation = value; Refresh(); } } private string fixedText; ////// Gets or sets the fixed text. /// ///The fixed text. [Description("固定文字"), Category("自定義")] public string FixedText { get { return fixedText; } set { fixedText = value; Refresh(); } } private Font textFont = DefaultFont; ////// Gets or sets the text font. /// ///The text font. [Description("值和固定文字字體"), Category("自定義")] public Font TextFont { get { return textFont; } set { textFont = value; Refresh(); } } private Color externalRoundColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the external round. /// ///The color of the external round. [Description("外圓顏色"), Category("自定義")] public Color ExternalRoundColor { get { return externalRoundColor; } set { externalRoundColor = value; Refresh(); } } private Color insideRoundColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the inside round. /// ///The color of the inside round. [Description("內(nèi)圓顏色"), Category("自定義")] public Color InsideRoundColor { get { return insideRoundColor; } set { insideRoundColor = value; Refresh(); } } private Color boundaryLineColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the boundary line. /// ///The color of the boundary line. [Description("邊界線顏色"), Category("自定義")] public Color BoundaryLineColor { get { return boundaryLineColor; } set { boundaryLineColor = value; Refresh(); } } private Color scaleColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the scale. /// ///The color of the scale. [Description("刻度顏色"), Category("自定義")] public Color ScaleColor { get { return scaleColor; } set { scaleColor = value; Refresh(); } } private Color scaleValueColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the scale value. /// ///The color of the scale value. [Description("刻度值文字顏色"), Category("自定義")] public Color ScaleValueColor { get { return scaleValueColor; } set { scaleValueColor = value; Refresh(); } } private Color pointerColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the pointer. /// ///The color of the pointer. [Description("指針顏色"), Category("自定義")] public Color PointerColor { get { return pointerColor; } set { pointerColor = value; Refresh(); } } private Color textColor = Color.FromArgb(255, 77, 59); ////// Gets or sets the color of the text. /// ///The color of the text. [Description("值和固定文字顏色"), Category("自定義")] public Color TextColor { get { return textColor; } set { textColor = value; Refresh(); } } Rectangle m_rectWorking; public UCMeter() { this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.Selectable, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.SetStyle(ControlStyles.UserPaint, true); this.SizeChanged += UCMeter1_SizeChanged; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.Size = new Size(350, 200); } void UCMeter1_SizeChanged(object sender, EventArgs e) { m_rectWorking = new Rectangle(10, 10, this.Width - 20, this.Height - 20); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); var g = e.Graphics; g.SetGDIHigh(); //外圓 float fltStartAngle = -90 - (meterDegrees) / 2 + 360; var r1 = new Rectangle(m_rectWorking.Location, new Size(m_rectWorking.Width, m_rectWorking.Width)); g.DrawArc(new Pen(new SolidBrush(externalRoundColor), 1), r1, fltStartAngle, meterDegrees); //內(nèi)圓 var r2 = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Top + (m_rectWorking.Width - m_rectWorking.Width / 4) / 2, m_rectWorking.Width / 4, m_rectWorking.Width / 4); g.DrawArc(new Pen(new SolidBrush(insideRoundColor), 1), r2, fltStartAngle, meterDegrees); //邊界線 if (meterDegrees != 360) { float fltAngle = fltStartAngle - 180; float intY = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float intX = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - m_rectWorking.Width / 8) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - (m_rectWorking.Width / 8 * Math.Cos(Math.PI * (fltAngle / 180.00F))))); g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(intX, intY), new PointF(fltX1, fltY1)); g.DrawLine(new Pen(new SolidBrush(boundaryLineColor), 1), new PointF(m_rectWorking.Right - (fltX1 - m_rectWorking.Left), fltY1), new PointF(m_rectWorking.Right - (intX - m_rectWorking.Left), intY)); } //分割線 int _splitCount = splitCount * 2; float fltSplitValue = (float)meterDegrees / (float)_splitCount; for (int i = 0; i <= _splitCount; i++) { float fltAngle = (fltStartAngle + fltSplitValue * i - 180) % 360; float fltY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float fltX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); float fltY2 = 0; float fltX2 = 0; if (i % 2 == 0) { fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 10) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); if (!(meterDegrees == 360 && i == _splitCount)) { decimal decValue = minValue + (maxValue - minValue) / _splitCount * i; var txtSize = g.MeasureString(decValue.ToString("0.##"), this.Font); float fltFY1 = (float)(m_rectWorking.Top - txtSize.Height / 2 + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); float fltFX1 = (float)(m_rectWorking.Left - txtSize.Width / 2 + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 20) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); g.DrawString(decValue.ToString("0.##"), Font, new SolidBrush(scaleValueColor), fltFX1, fltFY1); } } else { fltY2 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Sin(Math.PI * (fltAngle / 180.00F)))); fltX2 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 5) * Math.Cos(Math.PI * (fltAngle / 180.00F))))); } g.DrawLine(new Pen(new SolidBrush(scaleColor), i % 2 == 0 ? 2 : 1), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2)); } //值文字和固定文字 if (textLocation != MeterTextLocation.None) { string str = m_value.ToString("0.##"); var txtSize = g.MeasureString(str, textFont); float fltY = m_rectWorking.Top + m_rectWorking.Width / 4 - txtSize.Height / 2; float fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2; g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY)); if (!string.IsNullOrEmpty(fixedText)) { str = fixedText; txtSize = g.MeasureString(str, textFont); fltY = m_rectWorking.Top + m_rectWorking.Width / 4 + txtSize.Height / 2; fltX = m_rectWorking.Left + m_rectWorking.Width / 2 - txtSize.Width / 2; g.DrawString(str, textFont, new SolidBrush(textColor), new PointF(fltX, fltY)); } } //畫指針 g.FillEllipse(new SolidBrush(Color.FromArgb(100, pointerColor.R, pointerColor.G, pointerColor.B)), new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 10, m_rectWorking.Top + m_rectWorking.Width / 2 - 10, 20, 20)); g.FillEllipse(Brushes.Red, new Rectangle(m_rectWorking.Left + m_rectWorking.Width / 2 - 5, m_rectWorking.Top + m_rectWorking.Width / 2 - 5, 10, 10)); float fltValueAngle = (fltStartAngle + ((float)(m_value - minValue) / (float)(maxValue - minValue)) * (float)meterDegrees - 180) % 360; float intValueY1 = (float)(m_rectWorking.Top + m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Sin(Math.PI * (fltValueAngle / 180.00F)))); float intValueX1 = (float)(m_rectWorking.Left + (m_rectWorking.Width / 2 - ((m_rectWorking.Width / 2 - 30) * Math.Cos(Math.PI * (fltValueAngle / 180.00F))))); g.DrawLine(new Pen(new SolidBrush(pointerColor), 3), intValueX1, intValueY1, m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + m_rectWorking.Width / 2); } } ////// Enum MeterTextLocation /// public enum MeterTextLocation { ////// The none /// None, ////// The top /// Top, ////// The bottom /// Bottom }}
以上是“c#中Winform自定義控件如何實(shí)現(xiàn)儀表盤功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!