前提
成都創(chuàng)新互聯(lián)主營合陽網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā),合陽h5小程序制作搭建,合陽網(wǎng)站營銷推廣歡迎合陽等地區(qū)企業(yè)咨詢入行已經(jīng)7,8年了,一直想做一套漂亮點的自定義控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
碼云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
NuGet
Install-Package HZH_Controls
目錄
https://www.cnblogs.com/bfyx/p/11364884.html
用處及效果

準備工作
依然使用GDI+畫的,不懂的話就百度一下吧
另外主要用到了三角函數(shù),如果不懂,可以向初中的數(shù)學老師再問問(你也可以百度一下)
開始
添加一個類UCMeter 繼承 UserControl
首先添加一個需要控制的屬性
private int splitCount = 10;
/// <summary>
/// Gets or sets the split count.
/// </summary>
/// <value>The split count.</value>
[Description("分隔刻度數(shù)量,>1"), Category("自定義")]
public int SplitCount
{
get { return splitCount; }
set
{
if (value < 1)
return;
splitCount = value;
Refresh();
}
}
private int meterDegrees = 150;
/// <summary>
/// Gets or sets the meter degrees.
/// </summary>
/// <value>The meter degrees.</value>
[Description("表盤跨度角度,0-360"), Category("自定義")]
public int MeterDegrees
{
get { return meterDegrees; }
set
{
if (value > 360 || value <= 0)
return;
meterDegrees = value;
Refresh();
}
}
private decimal minValue = 0;
/// <summary>
/// Gets or sets the minimum value.
/// </summary>
/// <value>The minimum value.</value>
[Description("最小值,<MaxValue"), Category("自定義")]
public decimal MinValue
{
get { return minValue; }
set
{
if (value >= maxValue)
return;
minValue = value;
Refresh();
}
}
private decimal maxValue = 100;
/// <summary>
/// Gets or sets the maximum value.
/// </summary>
/// <value>The maximum value.</value>
[Description("大值,>MinValue"), Category("自定義")]
public decimal MaxValue
{
get { return maxValue; }
set
{
if (value <= minValue)
return;
maxValue = value;
Refresh();
}
}
/// <summary>
/// 獲取或設(shè)置控件顯示的文字的字體。
/// </summary>
/// <value>The font.</value>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
[Description("刻度字體"), Category("自定義")]
public override Font Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
Refresh();
}
}
private decimal m_value = 0;
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>The value.</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;
/// <summary>
/// Gets or sets the text location.
/// </summary>
/// <value>The text location.</value>
[Description("值和固定文字顯示位置"), Category("自定義")]
public MeterTextLocation TextLocation
{
get { return textLocation; }
set
{
textLocation = value;
Refresh();
}
}
private string fixedText;
/// <summary>
/// Gets or sets the fixed text.
/// </summary>
/// <value>The fixed text.</value>
[Description("固定文字"), Category("自定義")]
public string FixedText
{
get { return fixedText; }
set
{
fixedText = value;
Refresh();
}
}
private Font textFont = DefaultFont;
/// <summary>
/// Gets or sets the text font.
/// </summary>
/// <value>The text font.</value>
[Description("值和固定文字字體"), Category("自定義")]
public Font TextFont
{
get { return textFont; }
set
{
textFont = value;
Refresh();
}
}
private Color externalRoundColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the external round.
/// </summary>
/// <value>The color of the external round.</value>
[Description("外圓顏色"), Category("自定義")]
public Color ExternalRoundColor
{
get { return externalRoundColor; }
set
{
externalRoundColor = value;
Refresh();
}
}
private Color insideRoundColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the inside round.
/// </summary>
/// <value>The color of the inside round.</value>
[Description("內(nèi)圓顏色"), Category("自定義")]
public Color InsideRoundColor
{
get { return insideRoundColor; }
set
{
insideRoundColor = value;
Refresh();
}
}
private Color boundaryLineColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the boundary line.
/// </summary>
/// <value>The color of the boundary line.</value>
[Description("邊界線顏色"), Category("自定義")]
public Color BoundaryLineColor
{
get { return boundaryLineColor; }
set
{
boundaryLineColor = value;
Refresh();
}
}
private Color scaleColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the scale.
/// </summary>
/// <value>The color of the scale.</value>
[Description("刻度顏色"), Category("自定義")]
public Color ScaleColor
{
get { return scaleColor; }
set
{
scaleColor = value;
Refresh();
}
}
private Color scaleValueColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the scale value.
/// </summary>
/// <value>The color of the scale value.</value>
[Description("刻度值文字顏色"), Category("自定義")]
public Color ScaleValueColor
{
get { return scaleValueColor; }
set
{
scaleValueColor = value;
Refresh();
}
}
private Color pointerColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the pointer.
/// </summary>
/// <value>The color of the pointer.</value>
[Description("指針顏色"), Category("自定義")]
public Color PointerColor
{
get { return pointerColor; }
set
{
pointerColor = value;
Refresh();
}
}
private Color textColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the text.
/// </summary>
/// <value>The color of the text.</value>
[Description("值和固定文字顏色"), Category("自定義")]
public Color TextColor
{
get { return textColor; }
set
{
textColor = value;
Refresh();
}
}
Rectangle m_rectWorking;另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
當前名稱:c#Winform自定義控件-儀表盤功能-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://chinadenli.net/article28/cophcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、搜索引擎優(yōu)化、移動網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、微信小程序、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容