Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
42a042beb3 | ||
![]() |
123427892e | ||
![]() |
0b7f218b3c | ||
![]() |
c5e5a11188 | ||
![]() |
8bf338e488 | ||
![]() |
0d989a75ea | ||
![]() |
00897c5cc5 | ||
![]() |
cd04f9cf19 | ||
![]() |
7fd73a8808 | ||
![]() |
b9c87e15e8 | ||
![]() |
4f75336ed5 | ||
![]() |
8fce03fff2 | ||
![]() |
42c453820c | ||
![]() |
dc503f0eea | ||
![]() |
76426019e3 |
@ -12,7 +12,7 @@ namespace Sunny.UI.Demo
|
||||
var styles = UIStyles.PopularStyles();
|
||||
foreach (UIStyle style in styles)
|
||||
{
|
||||
ToolStripMenuItem item = new ToolStripMenuItem(style.DisplayText()) { Tag = style };
|
||||
ToolStripMenuItem item = new ToolStripMenuItem(style.Description()) { Tag = style };
|
||||
item.Click += Item_Click;
|
||||
uiContextMenuStrip1.Items.Add(item);
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI.Demo
|
||||
{
|
||||
/// <summary>
|
||||
/// Windows10、Windows11 建议用UIForm2,更接近原生窗体使用体验,用UIForm也可以
|
||||
/// WindowsXP、Windows7 建议使用UIForm
|
||||
/// WindowsXP、Windows7、Windows10、Windows11 建议使用 UIForm
|
||||
/// Windows10、Windows11 可尝试使用 UIForm2,更接近原生窗体使用体验,用 UIForm 也可以
|
||||
/// </summary>
|
||||
public partial class FMain : UIForm2
|
||||
public partial class FMain : UIForm
|
||||
{
|
||||
public FMain()
|
||||
{
|
||||
@ -97,7 +97,7 @@ namespace Sunny.UI.Demo
|
||||
var styles = UIStyles.PopularStyles();
|
||||
foreach (UIStyle style in styles)
|
||||
{
|
||||
uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], style.DisplayText(), style.Value());
|
||||
uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], style.Description(), style.Value());
|
||||
}
|
||||
|
||||
var node = uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], "字体图标", 99999);
|
||||
@ -115,6 +115,7 @@ namespace Sunny.UI.Demo
|
||||
uiNavMenu1.SelectPage(1002);
|
||||
|
||||
uiPanel2.Text = Text = Version;
|
||||
//设置全局热键
|
||||
RegisterHotKey(UI.ModifierKeys.Shift, Keys.F8);
|
||||
|
||||
//根据页面类型获取页面
|
||||
@ -176,6 +177,11 @@ namespace Sunny.UI.Demo
|
||||
Process.Start("https://gitee.com/yhuse/SunnyUI");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局热键事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Form1_HotKeyEventHandler(object sender, HotKeyEventArgs e)
|
||||
{
|
||||
if (e.hotKey.ModifierKey == UI.ModifierKeys.Shift && e.hotKey.Key == Keys.F8)
|
||||
|
18
SunnyUI.Demo/Industrial/FLed.Designer.cs
generated
18
SunnyUI.Demo/Industrial/FLed.Designer.cs
generated
@ -56,6 +56,7 @@ namespace Sunny.UI.Demo
|
||||
this.uiDigitalLabel2 = new Sunny.UI.UIDigitalLabel();
|
||||
this.uiDigitalLabel1 = new Sunny.UI.UIDigitalLabel();
|
||||
this.uiLine4 = new Sunny.UI.UILine();
|
||||
this.uiBattery7 = new Sunny.UI.UIBattery();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// uiBattery6
|
||||
@ -170,7 +171,7 @@ namespace Sunny.UI.Demo
|
||||
this.uiLedStopwatch1.Name = "uiLedStopwatch1";
|
||||
this.uiLedStopwatch1.Size = new System.Drawing.Size(190, 34);
|
||||
this.uiLedStopwatch1.TabIndex = 61;
|
||||
this.uiLedStopwatch1.Text = "12:50";
|
||||
this.uiLedStopwatch1.Text = "01:05";
|
||||
//
|
||||
// uiLedDisplay1
|
||||
//
|
||||
@ -359,11 +360,25 @@ namespace Sunny.UI.Demo
|
||||
this.uiLine4.Text = "UIDigitalLabel";
|
||||
this.uiLine4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// uiBattery7
|
||||
//
|
||||
this.uiBattery7.Font = new System.Drawing.Font("宋体", 12F);
|
||||
this.uiBattery7.Location = new System.Drawing.Point(42, 410);
|
||||
this.uiBattery7.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
this.uiBattery7.Name = "uiBattery7";
|
||||
this.uiBattery7.Size = new System.Drawing.Size(73, 105);
|
||||
this.uiBattery7.SymbolOffset = new System.Drawing.Point(1, 3);
|
||||
this.uiBattery7.SymbolRotate = 270;
|
||||
this.uiBattery7.SymbolSize = 100;
|
||||
this.uiBattery7.TabIndex = 110;
|
||||
this.uiBattery7.Text = "uiBattery7";
|
||||
//
|
||||
// FLed
|
||||
//
|
||||
this.AllowShowTitle = true;
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(800, 555);
|
||||
this.Controls.Add(this.uiBattery7);
|
||||
this.Controls.Add(this.uiLine4);
|
||||
this.Controls.Add(this.uiDigitalLabel2);
|
||||
this.Controls.Add(this.uiDigitalLabel1);
|
||||
@ -426,5 +441,6 @@ namespace Sunny.UI.Demo
|
||||
private UIDigitalLabel uiDigitalLabel2;
|
||||
private UIDigitalLabel uiDigitalLabel1;
|
||||
private UILine uiLine4;
|
||||
private UIBattery uiBattery7;
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
private void timer1_Tick(object sender, System.EventArgs e)
|
||||
{
|
||||
value++;
|
||||
uiBattery1.Power = value;
|
||||
uiBattery7.Power = uiBattery1.Power = value;
|
||||
uiLedDisplay1.Text = value + " Ω";
|
||||
uiDigitalLabel2.Value += 0.1;
|
||||
}
|
||||
|
118
SunnyUI.Demo/Industrial/FLight.Designer.cs
generated
118
SunnyUI.Demo/Industrial/FLight.Designer.cs
generated
@ -45,6 +45,12 @@ namespace Sunny.UI.Demo
|
||||
this.uiLedBulb6 = new Sunny.UI.UILedBulb();
|
||||
this.uiLight5 = new Sunny.UI.UILight();
|
||||
this.uiLight6 = new Sunny.UI.UILight();
|
||||
this.uiStatusBox1 = new Sunny.UI.UIStatusBox();
|
||||
this.uiLine1 = new Sunny.UI.UILine();
|
||||
this.uiButton1 = new Sunny.UI.UIButton();
|
||||
this.uiButton2 = new Sunny.UI.UIButton();
|
||||
this.uiButton3 = new Sunny.UI.UIButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.uiStatusBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// uiLedBulb4
|
||||
@ -78,7 +84,9 @@ namespace Sunny.UI.Demo
|
||||
//
|
||||
// uiLine8
|
||||
//
|
||||
this.uiLine8.BackColor = System.Drawing.Color.Transparent;
|
||||
this.uiLine8.Font = new System.Drawing.Font("宋体", 12F);
|
||||
this.uiLine8.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
|
||||
this.uiLine8.Location = new System.Drawing.Point(381, 55);
|
||||
this.uiLine8.MinimumSize = new System.Drawing.Size(16, 16);
|
||||
this.uiLine8.Name = "uiLine8";
|
||||
@ -144,7 +152,9 @@ namespace Sunny.UI.Demo
|
||||
//
|
||||
// uiLine2
|
||||
//
|
||||
this.uiLine2.BackColor = System.Drawing.Color.Transparent;
|
||||
this.uiLine2.Font = new System.Drawing.Font("宋体", 12F);
|
||||
this.uiLine2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
|
||||
this.uiLine2.Location = new System.Drawing.Point(30, 55);
|
||||
this.uiLine2.MinimumSize = new System.Drawing.Size(16, 16);
|
||||
this.uiLine2.Name = "uiLine2";
|
||||
@ -223,11 +233,113 @@ namespace Sunny.UI.Demo
|
||||
this.uiLight6.TabIndex = 75;
|
||||
this.uiLight6.Text = "uiLight6";
|
||||
//
|
||||
// uiStatusBox1
|
||||
//
|
||||
this.uiStatusBox1.Image = global::Sunny.UI.Demo.Properties.Resources.led_g;
|
||||
this.uiStatusBox1.Location = new System.Drawing.Point(30, 272);
|
||||
this.uiStatusBox1.Name = "uiStatusBox1";
|
||||
this.uiStatusBox1.Size = new System.Drawing.Size(36, 36);
|
||||
this.uiStatusBox1.Status1 = global::Sunny.UI.Demo.Properties.Resources.led_g;
|
||||
this.uiStatusBox1.Status2 = global::Sunny.UI.Demo.Properties.Resources.led_y;
|
||||
this.uiStatusBox1.Status3 = global::Sunny.UI.Demo.Properties.Resources.led_r;
|
||||
this.uiStatusBox1.TabIndex = 77;
|
||||
this.uiStatusBox1.TabStop = false;
|
||||
//
|
||||
// uiLine1
|
||||
//
|
||||
this.uiLine1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.uiLine1.Font = new System.Drawing.Font("宋体", 12F);
|
||||
this.uiLine1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
|
||||
this.uiLine1.Location = new System.Drawing.Point(30, 230);
|
||||
this.uiLine1.MinimumSize = new System.Drawing.Size(16, 16);
|
||||
this.uiLine1.Name = "uiLine1";
|
||||
this.uiLine1.Size = new System.Drawing.Size(319, 20);
|
||||
this.uiLine1.TabIndex = 79;
|
||||
this.uiLine1.Text = "UILight";
|
||||
this.uiLine1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// uiButton1
|
||||
//
|
||||
this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(190)))), ((int)(((byte)(40)))));
|
||||
this.uiButton1.FillColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(190)))), ((int)(((byte)(40)))));
|
||||
this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(139)))), ((int)(((byte)(203)))), ((int)(((byte)(83)))));
|
||||
this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
|
||||
this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
|
||||
this.uiButton1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.uiButton1.LightColor = System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(251)))), ((int)(((byte)(241)))));
|
||||
this.uiButton1.Location = new System.Drawing.Point(78, 273);
|
||||
this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
this.uiButton1.Name = "uiButton1";
|
||||
this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(190)))), ((int)(((byte)(40)))));
|
||||
this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(139)))), ((int)(((byte)(203)))), ((int)(((byte)(83)))));
|
||||
this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
|
||||
this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
|
||||
this.uiButton1.Size = new System.Drawing.Size(75, 35);
|
||||
this.uiButton1.Style = Sunny.UI.UIStyle.Custom;
|
||||
this.uiButton1.TabIndex = 80;
|
||||
this.uiButton1.Text = "切换";
|
||||
this.uiButton1.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
|
||||
//
|
||||
// uiButton2
|
||||
//
|
||||
this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(155)))), ((int)(((byte)(40)))));
|
||||
this.uiButton2.FillColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(155)))), ((int)(((byte)(40)))));
|
||||
this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(227)))), ((int)(((byte)(175)))), ((int)(((byte)(83)))));
|
||||
this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(176)))), ((int)(((byte)(124)))), ((int)(((byte)(32)))));
|
||||
this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(176)))), ((int)(((byte)(124)))), ((int)(((byte)(32)))));
|
||||
this.uiButton2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.uiButton2.LightColor = System.Drawing.Color.FromArgb(((int)(((byte)(253)))), ((int)(((byte)(249)))), ((int)(((byte)(241)))));
|
||||
this.uiButton2.Location = new System.Drawing.Point(159, 273);
|
||||
this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
this.uiButton2.Name = "uiButton2";
|
||||
this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(155)))), ((int)(((byte)(40)))));
|
||||
this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(227)))), ((int)(((byte)(175)))), ((int)(((byte)(83)))));
|
||||
this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(176)))), ((int)(((byte)(124)))), ((int)(((byte)(32)))));
|
||||
this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(176)))), ((int)(((byte)(124)))), ((int)(((byte)(32)))));
|
||||
this.uiButton2.Size = new System.Drawing.Size(75, 35);
|
||||
this.uiButton2.Style = Sunny.UI.UIStyle.Custom;
|
||||
this.uiButton2.TabIndex = 81;
|
||||
this.uiButton2.Text = "切换";
|
||||
this.uiButton2.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
|
||||
//
|
||||
// uiButton3
|
||||
//
|
||||
this.uiButton3.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.uiButton3.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
|
||||
this.uiButton3.FillColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
|
||||
this.uiButton3.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(115)))), ((int)(((byte)(115)))));
|
||||
this.uiButton3.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(184)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.uiButton3.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(184)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.uiButton3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.uiButton3.LightColor = System.Drawing.Color.FromArgb(((int)(((byte)(253)))), ((int)(((byte)(243)))), ((int)(((byte)(243)))));
|
||||
this.uiButton3.Location = new System.Drawing.Point(240, 273);
|
||||
this.uiButton3.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
this.uiButton3.Name = "uiButton3";
|
||||
this.uiButton3.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
|
||||
this.uiButton3.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(115)))), ((int)(((byte)(115)))));
|
||||
this.uiButton3.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(184)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.uiButton3.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(184)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
|
||||
this.uiButton3.Size = new System.Drawing.Size(75, 35);
|
||||
this.uiButton3.Style = Sunny.UI.UIStyle.Custom;
|
||||
this.uiButton3.TabIndex = 82;
|
||||
this.uiButton3.Text = "切换";
|
||||
this.uiButton3.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.uiButton3.Click += new System.EventHandler(this.uiButton3_Click);
|
||||
//
|
||||
// FLight
|
||||
//
|
||||
this.AllowShowTitle = true;
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.uiButton3);
|
||||
this.Controls.Add(this.uiButton2);
|
||||
this.Controls.Add(this.uiButton1);
|
||||
this.Controls.Add(this.uiLine1);
|
||||
this.Controls.Add(this.uiStatusBox1);
|
||||
this.Controls.Add(this.uiLight5);
|
||||
this.Controls.Add(this.uiLight6);
|
||||
this.Controls.Add(this.uiLedBulb5);
|
||||
@ -247,6 +359,7 @@ namespace Sunny.UI.Demo
|
||||
this.ShowTitle = true;
|
||||
this.Symbol = 362751;
|
||||
this.Text = "Light";
|
||||
((System.ComponentModel.ISupportInitialize)(this.uiStatusBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@ -267,5 +380,10 @@ namespace Sunny.UI.Demo
|
||||
private UILedBulb uiLedBulb6;
|
||||
private UILight uiLight5;
|
||||
private UILight uiLight6;
|
||||
private UIStatusBox uiStatusBox1;
|
||||
private UILine uiLine1;
|
||||
private UIButton uiButton1;
|
||||
private UIButton uiButton2;
|
||||
private UIButton uiButton3;
|
||||
}
|
||||
}
|
@ -6,5 +6,27 @@
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public enum LightState
|
||||
{
|
||||
Green = 1,
|
||||
Yellow = 2,
|
||||
Red = 3
|
||||
}
|
||||
|
||||
private void uiButton1_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
uiStatusBox1.Status = (int)LightState.Green;
|
||||
}
|
||||
|
||||
private void uiButton2_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
uiStatusBox1.Status = (int)LightState.Yellow;
|
||||
}
|
||||
|
||||
private void uiButton3_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
uiStatusBox1.Status = (int)LightState.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
SunnyUI.Demo/Properties/Resources.Designer.cs
generated
30
SunnyUI.Demo/Properties/Resources.Designer.cs
generated
@ -470,6 +470,36 @@ namespace Sunny.UI.Demo.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap led_g {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("led_g", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap led_r {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("led_r", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap led_y {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("led_y", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
|
@ -214,6 +214,15 @@
|
||||
<data name="lazio" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\lazio.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="led_g" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\led_g.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="led_r" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\led_r.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="led_y" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\led_y.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="mallorca" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\mallorca.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
|
BIN
SunnyUI.Demo/Resources/led_g.png
Normal file
BIN
SunnyUI.Demo/Resources/led_g.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
BIN
SunnyUI.Demo/Resources/led_r.png
Normal file
BIN
SunnyUI.Demo/Resources/led_r.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
BIN
SunnyUI.Demo/Resources/led_y.png
Normal file
BIN
SunnyUI.Demo/Resources/led_y.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
@ -41,36 +41,33 @@
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SunnyUI, Version=3.8.2.0, Culture=neutral, PublicKeyToken=27d7d2e821d97aeb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.3.8.2\lib\net472\SunnyUI.dll</HintPath>
|
||||
<Reference Include="SunnyUI, Version=3.8.3.0, Culture=neutral, PublicKeyToken=27d7d2e821d97aeb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.3.8.3\lib\net472\SunnyUI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SunnyUI.COM, Version=6.7.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.COM.6.7.1\lib\net472\SunnyUI.COM.dll</HintPath>
|
||||
<Reference Include="SunnyUI.COM, Version=9.0.3.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.COM.9.0.3.1\lib\net472\SunnyUI.COM.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SunnyUI.Common, Version=3.8.2.0, Culture=neutral, PublicKeyToken=5a271fb7ba597231, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.Common.3.8.2\lib\net472\SunnyUI.Common.dll</HintPath>
|
||||
<Reference Include="SunnyUI.Common, Version=3.8.3.0, Culture=neutral, PublicKeyToken=5a271fb7ba597231, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.Common.3.8.3\lib\net472\SunnyUI.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SunnyUI.FrameDecoder, Version=7.6.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.FrameDecoder.7.6.0\lib\net472\SunnyUI.FrameDecoder.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SunnyUI.Serialization, Version=6.6.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SunnyUI.Serialization.6.6.0\lib\net472\SunnyUI.Serialization.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.6.0\lib\net462\System.Buffers.dll</HintPath>
|
||||
<Reference Include="System.Buffers, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Design" />
|
||||
<Reference Include="System.Memory, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.6.0\lib\net462\System.Memory.dll</HintPath>
|
||||
<Reference Include="System.Memory, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.6.3\lib\net462\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.6.0\lib\net462\System.Numerics.Vectors.dll</HintPath>
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@ -775,6 +772,9 @@
|
||||
<None Include="Resources\Tom.gif" />
|
||||
<None Include="Resources\Sunny24.png" />
|
||||
<None Include="Resources\SunnyUI72.png" />
|
||||
<None Include="Resources\led_g.png" />
|
||||
<None Include="Resources\led_r.png" />
|
||||
<None Include="Resources\led_y.png" />
|
||||
<Content Include="SunnyUI.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
|
@ -9,7 +9,15 @@
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.3.0" newVersion="6.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
|
@ -1,12 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="SunnyUI" version="3.8.2" targetFramework="net472" />
|
||||
<package id="SunnyUI.COM" version="6.7.1" targetFramework="net472" />
|
||||
<package id="SunnyUI.Common" version="3.8.2" targetFramework="net472" />
|
||||
<package id="SunnyUI" version="3.8.3" targetFramework="net472" />
|
||||
<package id="SunnyUI.COM" version="9.0.3.1" targetFramework="net472" />
|
||||
<package id="SunnyUI.Common" version="3.8.3" targetFramework="net472" />
|
||||
<package id="SunnyUI.FrameDecoder" version="7.6.0" targetFramework="net472" />
|
||||
<package id="SunnyUI.Serialization" version="6.6.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.6.0" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.6.0" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.6.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.0" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.6.1" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.6.3" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net472" />
|
||||
</packages>
|
@ -50,6 +50,7 @@ namespace Sunny.UI
|
||||
/// 柱状图
|
||||
/// </summary>
|
||||
[ToolboxItem(true)]
|
||||
[Description("柱状图控件")]
|
||||
public class UIBarChart : UIChart
|
||||
{
|
||||
private bool NeedDraw;
|
||||
|
@ -32,7 +32,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true), Description("甜甜圈图")]
|
||||
[ToolboxItem(true), Description("甜甜圈图控件")]
|
||||
public sealed class UIDoughnutChart : UIChart
|
||||
{
|
||||
/// <summary>
|
||||
@ -249,9 +249,9 @@ namespace Sunny.UI
|
||||
{
|
||||
Angle angle = Angles[pieIndex][azIndex];
|
||||
PointF pf = angle.Center;
|
||||
if (Drawing.CalcDistance(e.Location, pf) > angle.Outer) continue;
|
||||
if (Drawing.CalcDistance(e.Location, pf) < angle.Inner) continue;
|
||||
double az = Drawing.CalcAngle(e.Location, pf);
|
||||
if (e.Location.CalcDistance(pf) > angle.Outer) continue;
|
||||
if (e.Location.CalcDistance(pf) < angle.Inner) continue;
|
||||
double az = e.Location.CalcAngle(pf);
|
||||
if (az >= angle.Start && az <= angle.Start + angle.Sweep)
|
||||
{
|
||||
SetPieAndAzIndex(pieIndex, azIndex);
|
||||
|
@ -69,6 +69,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("曲线图控件")]
|
||||
public class UILineChart : UIChart
|
||||
{
|
||||
protected bool NeedDraw;
|
||||
|
@ -32,6 +32,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("饼状图控件")]
|
||||
public sealed class UIPieChart : UIChart
|
||||
{
|
||||
/// <summary>
|
||||
@ -273,9 +274,9 @@ namespace Sunny.UI
|
||||
if (!e.Location.InRect(rect)) continue;
|
||||
|
||||
PointF pf = new PointF(rect.Left + rect.Width / 2.0f, rect.Top + rect.Height / 2.0f);
|
||||
if (Drawing.CalcDistance(e.Location, pf) * 2 > rect.Width) continue;
|
||||
if (e.Location.CalcDistance(pf) * 2 > rect.Width) continue;
|
||||
|
||||
double az = Drawing.CalcAngle(e.Location, pf);
|
||||
double az = e.Location.CalcAngle(pf);
|
||||
for (int azIndex = 0; azIndex < Option.Series[pieIndex].Data.Count; azIndex++)
|
||||
{
|
||||
Angle angle = Angles[pieIndex][azIndex];
|
||||
|
743
SunnyUI/Common/UBaseConfig.cs
Normal file
743
SunnyUI/Common/UBaseConfig.cs
Normal file
@ -0,0 +1,743 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.Common.dll can be used for free under the MIT license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UBaseConfig.cs
|
||||
* 文件说明: 配置文件基类
|
||||
* 当前版本: V3.1
|
||||
* 创建日期: 2020-01-01
|
||||
*
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置文件基类
|
||||
/// </summary>
|
||||
/// <typeparam name="TConfig">类型</typeparam>
|
||||
public abstract class BaseConfig<TConfig> where TConfig : BaseConfig<TConfig>, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体对象
|
||||
/// </summary>
|
||||
protected static TConfig current;
|
||||
|
||||
/// <summary>
|
||||
/// 配置文件描述
|
||||
/// </summary>
|
||||
public static string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
var fileanddesc = ConfigHelper.GetConfigFile<TConfig>();
|
||||
return fileanddesc.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置文件名
|
||||
/// </summary>
|
||||
public static string ConfigFile
|
||||
{
|
||||
get
|
||||
{
|
||||
var fileanddesc = ConfigHelper.GetConfigFile<TConfig>();
|
||||
return fileanddesc.Item1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前可执行文件路径,末尾包括\
|
||||
/// </summary>
|
||||
/// <returns>结果</returns>
|
||||
private static string CurrentDir()
|
||||
{
|
||||
return Environment.CurrentDirectory.DealPath();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前实例。通过置空可以使其重新加载。
|
||||
/// </summary>
|
||||
public static TConfig Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (current != null)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
// 现在没有对象,尝试加载,若返回null则实例化一个新的
|
||||
current = CreateNew();
|
||||
if (!current.Load(CurrentDir() + ConfigFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
// 根据配置,有可能不保存,直接返回默认
|
||||
current.Save();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
set => current = value;
|
||||
}
|
||||
|
||||
private static TConfig CreateNew()
|
||||
{
|
||||
TConfig config = new TConfig();
|
||||
config.SetDefault();
|
||||
return config;
|
||||
}
|
||||
|
||||
/// <summary>保存到配置文件中去</summary>
|
||||
public void Save()
|
||||
{
|
||||
Save(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载指定配置文件
|
||||
/// </summary>
|
||||
/// <returns>结果</returns>
|
||||
public bool Load()
|
||||
{
|
||||
return Load(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密
|
||||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <returns>加密后字符串</returns>
|
||||
public string Encrypt(string str)
|
||||
{
|
||||
Random random = new Random();
|
||||
var value = random.Next(100000, 999999);
|
||||
string tmp = str + value.ToString();
|
||||
return tmp.DesEncrypt();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密
|
||||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <returns>解密后字符串</returns>
|
||||
public string Decrypt(string str)
|
||||
{
|
||||
string result = str.DesDecrypt();
|
||||
return result.Left(result.Length - 6);
|
||||
}
|
||||
|
||||
/// <summary>加载指定配置文件</summary>
|
||||
/// <param name="filename">文件名</param>
|
||||
/// <returns>结果</returns>
|
||||
public abstract bool Load(string filename);
|
||||
|
||||
/// <summary>保存到配置文件中去</summary>
|
||||
/// <param name="filename">文件名</param>
|
||||
public abstract void Save(string filename);
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认值
|
||||
/// </summary>
|
||||
public virtual void SetDefault()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 忽略此属性的配置存储
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class MapperIgnoreAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 忽略此属性的配置存储
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class IgnoreAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置文件帮助类
|
||||
/// </summary>
|
||||
public static class ConfigHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型是否能够转为指定基类
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <param name="baseType">基类</param>
|
||||
/// <returns>是否能够转为指定基类</returns>
|
||||
public static bool As(this Type type, Type baseType)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果基类是泛型定义
|
||||
if (baseType.IsGenericTypeDefinition && type.IsGenericType && !type.IsGenericTypeDefinition)
|
||||
{
|
||||
type = type.GetGenericTypeDefinition();
|
||||
}
|
||||
|
||||
if (type == baseType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (baseType.IsAssignableFrom(type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var rs = false;
|
||||
|
||||
// 接口
|
||||
if (baseType.IsInterface)
|
||||
{
|
||||
if (type.GetInterface(baseType.FullName) != null)
|
||||
{
|
||||
rs = true;
|
||||
}
|
||||
else
|
||||
foreach (var e in type.GetInterfaces())
|
||||
{
|
||||
if (e.IsGenericType && baseType.IsGenericTypeDefinition ? e.GetGenericTypeDefinition() == baseType : e == baseType)
|
||||
{
|
||||
rs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断是否子类时,支持只反射加载的程序集
|
||||
if (!rs && type.Assembly.ReflectionOnly)
|
||||
{
|
||||
// 反射加载时,需要特殊处理接口
|
||||
while (!rs && type != typeof(object))
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type.FullName == baseType.FullName && type.AssemblyQualifiedName == baseType.AssemblyQualifiedName)
|
||||
{
|
||||
rs = true;
|
||||
}
|
||||
|
||||
type = type.BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
/// <summary>是否泛型字典</summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns>是否泛型字典</returns>
|
||||
public static bool IsDictionary(this Type type) => type != null && type.IsGenericType && type.As(typeof(IDictionary<,>));
|
||||
|
||||
/// <summary>是否泛型列表</summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns>是否泛型列表</returns>
|
||||
public static bool IsList(this Type type)
|
||||
{
|
||||
return type != null && type.IsGenericType && type.As(typeof(IList<>));
|
||||
//return Array.IndexOf(type.GetInterfaces(), typeof(IEnumerable)) > -1;
|
||||
}
|
||||
|
||||
/// <summary>获取成员绑定的显示名,优先DisplayName,然后Description</summary>
|
||||
/// <param name="member">member</param>
|
||||
/// <returns>显示名</returns>
|
||||
public static string DisplayName(this PropertyInfo member)
|
||||
{
|
||||
var att = member.GetCustomAttribute<DisplayNameAttribute>();
|
||||
if (att != null && !att.DisplayName.IsNullOrWhiteSpace())
|
||||
{
|
||||
return att.DisplayName;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>获取成员绑定的显示名,优先DisplayName,然后Description</summary>
|
||||
/// <param name="member">member</param>
|
||||
/// <returns>显示名</returns>
|
||||
public static string Description(this PropertyInfo member)
|
||||
{
|
||||
var att2 = member.GetCustomAttribute<DescriptionAttribute>();
|
||||
if (att2 != null && !att2.Description.IsNullOrWhiteSpace())
|
||||
{
|
||||
return att2.Description;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取需要的属性,删除忽略的属性
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns>属性列表</returns>
|
||||
public static List<PropertyInfo> GetNeedProperties(this Type type)
|
||||
{
|
||||
var list = type.GetProperties();
|
||||
List<PropertyInfo> result = new List<PropertyInfo>();
|
||||
foreach (var info in list)
|
||||
{
|
||||
if (info.GetCustomAttribute<XmlIgnoreAttribute>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info.GetCustomAttribute<ConfigIgnoreAttribute>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info.GetCustomAttribute<MapperIgnoreAttribute>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info.GetCustomAttribute<IgnoreAttribute>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result.Add(info);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置文件路径
|
||||
/// </summary>
|
||||
/// <typeparam name="TConfig">类型</typeparam>
|
||||
/// <returns>文件名</returns>
|
||||
public static Tuple<string, string> GetConfigFile<TConfig>()
|
||||
{
|
||||
string filename;
|
||||
string description = "配置文件";
|
||||
var att = typeof(TConfig).GetCustomAttribute<ConfigFileAttribute>();
|
||||
if (att == null || att.FileName.IsNullOrWhiteSpace())
|
||||
{
|
||||
filename = $"{typeof(TConfig).Name}.cfg";
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = att.FileName;
|
||||
|
||||
if (!att.Description.IsNullOrEmpty())
|
||||
{
|
||||
description = att.Description;
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple<string, string>(filename, description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化属性
|
||||
/// </summary>
|
||||
/// <param name="config">配置类</param>
|
||||
/// <typeparam name="TConfig">类型</typeparam>
|
||||
/// <returns>节点</returns>
|
||||
/// <exception cref="ApplicationException">ApplicationException</exception>
|
||||
public static ConcurrentDictionary<string, Ident> InitIdents<TConfig>(TConfig config)
|
||||
{
|
||||
ConcurrentDictionary<string, Ident> idents = new ConcurrentDictionary<string, Ident>();
|
||||
var list = config.GetType().GetNeedProperties();
|
||||
foreach (PropertyInfo info in list)
|
||||
{
|
||||
Ident ident = new Ident
|
||||
{
|
||||
Key = info.Name,
|
||||
Show = true,
|
||||
Description = info.Description(),
|
||||
IsList = info.PropertyType.IsList()
|
||||
};
|
||||
|
||||
var section = info.GetCustomAttribute<ConfigSectionAttribute>();
|
||||
ident.Section = section != null ? section.Section : "";
|
||||
|
||||
var propertyatt = info.GetCustomAttribute<ConfigPropertyAttribute>();
|
||||
ident.Caption = propertyatt != null ? propertyatt.Caption : "";
|
||||
ident.Unit = propertyatt != null ? propertyatt.Unit : "";
|
||||
ident.Description = propertyatt != null ? propertyatt.Description : "";
|
||||
|
||||
var indexatt = info.GetCustomAttribute<ConfigIndexAttribute>();
|
||||
ident.Index = indexatt?.Index ?? short.MaxValue + idents.Count;
|
||||
ident.Show = indexatt == null || indexatt.Show;
|
||||
|
||||
if (ident.Description.IsNullOrEmpty())
|
||||
{
|
||||
ident.Description = info.DisplayName() ?? info.Description();
|
||||
}
|
||||
|
||||
if (ident.Description.IsNullOrEmpty())
|
||||
{
|
||||
ident.Description = "";
|
||||
}
|
||||
|
||||
if (!idents.ContainsKey(ident.Key))
|
||||
{
|
||||
idents.TryAdd(ident.Key, ident);
|
||||
}
|
||||
}
|
||||
|
||||
return idents;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 类型默认值
|
||||
/// </summary>
|
||||
/// <param name="targetType">类型</param>
|
||||
/// <returns>默认值</returns>
|
||||
public static object DefaultValue(Type targetType)
|
||||
{
|
||||
return targetType.IsValueType ? Activator.CreateInstance(targetType) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取对象数值
|
||||
/// </summary>
|
||||
/// <param name="config">配置文件</param>
|
||||
/// <param name="idents">节点</param>
|
||||
/// <typeparam name="TConfig">类型</typeparam>
|
||||
/// <exception cref="ApplicationException">ApplicationException</exception>
|
||||
public static void LoadConfigValue<TConfig>(TConfig config, ConcurrentDictionary<string, Ident> idents)
|
||||
{
|
||||
var list = config.GetType().GetNeedProperties();
|
||||
foreach (PropertyInfo info in list)
|
||||
{
|
||||
object defaultobj = info.GetValue(config, null);
|
||||
Type type = info.PropertyType;
|
||||
|
||||
if (type == typeof(string))
|
||||
{
|
||||
object value = idents[info.Name].Value;
|
||||
info.SetValue(config, Convert.ChangeType(value == null ? defaultobj : value, type), null);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ConvertEx.CanConvent(type))
|
||||
{
|
||||
object value = ConvertEx.StringToObject(idents[info.Name].Value, type, defaultobj);
|
||||
info.SetValue(config, Convert.ChangeType(value, type), null);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type.IsList())
|
||||
{
|
||||
Type[] genericTypes = type.GetGenericArguments();
|
||||
if (genericTypes.Length != 1)
|
||||
{
|
||||
throw new ApplicationException("转换出错: " + type.FullName);
|
||||
}
|
||||
|
||||
Type childtype = genericTypes[0];
|
||||
Type typeDataList = typeof(List<>).MakeGenericType(childtype);
|
||||
MethodInfo methodInfo = typeDataList.GetMethod("Add", BindingFlags.Public | BindingFlags.Instance);
|
||||
if (methodInfo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object listvalue = typeDataList.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, new object[] { });
|
||||
|
||||
foreach (string strvalue in idents[info.Name].Values)
|
||||
{
|
||||
if (childtype == typeof(string))
|
||||
{
|
||||
object value = strvalue;
|
||||
methodInfo.Invoke(listvalue, new[] { value });
|
||||
}
|
||||
else if (ConvertEx.CanConvent(childtype))
|
||||
{
|
||||
object value = ConvertEx.StringToObject(strvalue, childtype, DefaultValue(childtype));
|
||||
methodInfo.Invoke(listvalue, new[] { value });
|
||||
}
|
||||
}
|
||||
|
||||
info.SetValue(config, listvalue, null);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new ApplicationException("不支持此类型: " + type.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置对象数值
|
||||
/// </summary>
|
||||
/// <param name="config">配置文件</param>
|
||||
/// <param name="idents">节点</param>
|
||||
/// <typeparam name="TConfig">类型</typeparam>
|
||||
/// <exception cref="ApplicationException">ApplicationException</exception>
|
||||
public static void SaveConfigValue<TConfig>(TConfig config, ConcurrentDictionary<string, Ident> idents)
|
||||
{
|
||||
var list = config.GetType().GetNeedProperties();
|
||||
foreach (PropertyInfo info in list)
|
||||
{
|
||||
object obj = info.GetValue(config, null);
|
||||
Type type = info.PropertyType;
|
||||
|
||||
if (ConvertEx.CanConvent(type))
|
||||
{
|
||||
string value = ConvertEx.ObjectToString(obj, type);
|
||||
idents[info.Name].Value = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type.IsList())
|
||||
{
|
||||
Type[] genericTypes = type.GetGenericArguments();
|
||||
if (genericTypes.Length != 1)
|
||||
{
|
||||
throw new ApplicationException("转换出错: " + type.FullName);
|
||||
}
|
||||
|
||||
Type childtype = genericTypes[0];
|
||||
IEnumerable en = obj as IEnumerable;
|
||||
if (en == null)
|
||||
{
|
||||
throw new ApplicationException("转换出错: " + type.FullName);
|
||||
}
|
||||
|
||||
idents[info.Name].Values.Clear();
|
||||
foreach (object child in en)
|
||||
{
|
||||
if (ConvertEx.CanConvent(childtype))
|
||||
{
|
||||
idents[info.Name].Values.Add(ConvertEx.ObjectToString(child, childtype));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ApplicationException("不支持此类型: " + type.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new ApplicationException("不支持此类型: " + type.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>配置文件特性</summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ConfigFileAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置文件名
|
||||
/// </summary>
|
||||
public string FileName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置文件
|
||||
/// </summary>
|
||||
public ConfigFileAttribute() : this(string.Empty, string.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>配置文件</summary>
|
||||
/// <param name="fileName">文件名</param>
|
||||
/// <param name="description">描述</param>
|
||||
public ConfigFileAttribute(string fileName, string description = "")
|
||||
{
|
||||
FileName = fileName;
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据节点
|
||||
/// </summary>
|
||||
public class Ident
|
||||
{
|
||||
/// <summary>
|
||||
/// 节
|
||||
/// </summary>
|
||||
public string Section { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 键
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Caption { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位
|
||||
/// </summary>
|
||||
public string Unit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 序号
|
||||
/// </summary>
|
||||
public int Index { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示
|
||||
/// </summary>
|
||||
public bool Show { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ToString()
|
||||
/// </summary>
|
||||
/// <returns>String</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return Index + " [" + Section + "] " + Key + " = ?";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否是列表类型
|
||||
/// </summary>
|
||||
public bool IsList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 列表值
|
||||
/// </summary>
|
||||
public List<string> Values = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置属性节点特性
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ConfigSectionAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 节
|
||||
/// </summary>
|
||||
public string Section { get; }
|
||||
|
||||
/// <summary>属性节点特性</summary>
|
||||
/// <param name="section">节</param>
|
||||
public ConfigSectionAttribute(string section)
|
||||
{
|
||||
Section = section;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置属性描述特性
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ConfigPropertyAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Caption { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位
|
||||
/// </summary>
|
||||
public string Unit { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置文件属性
|
||||
/// </summary>
|
||||
/// <param name="caption">标题</param>
|
||||
/// <param name="unit">单位</param>
|
||||
/// <param name="description">描述</param>
|
||||
public ConfigPropertyAttribute(string caption, string description = "", string unit = "")
|
||||
{
|
||||
Caption = caption;
|
||||
Unit = unit;
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 忽略此属性的配置存储
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ConfigIgnoreAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置序号描述特性
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ConfigIndexAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 序号
|
||||
/// </summary>
|
||||
public int Index { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示
|
||||
/// </summary>
|
||||
public bool Show { get; }
|
||||
|
||||
/// <summary>配置序号特性</summary>
|
||||
/// <param name="index">序号</param>
|
||||
/// <param name="show">是否显示</param>
|
||||
public ConfigIndexAttribute(int index, bool show = true)
|
||||
{
|
||||
Index = index;
|
||||
Show = show;
|
||||
}
|
||||
}
|
||||
}
|
371
SunnyUI/Common/UConvertEx.cs
Normal file
371
SunnyUI/Common/UConvertEx.cs
Normal file
@ -0,0 +1,371 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.Common.dll can be used for free under the MIT license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UConvertEx.cs
|
||||
* 文件说明: 对象转换扩展类
|
||||
* 当前版本: V3.1
|
||||
* 创建日期: 2020-01-01
|
||||
*
|
||||
* 2020-11-20: V3.0.0 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 对象转换扩展类
|
||||
/// </summary>
|
||||
public static class ConvertEx
|
||||
{
|
||||
/// <summary>
|
||||
/// 可以对象和字符串互相转换的类型
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns>结果</returns>
|
||||
public static bool CanConvent(Type type)
|
||||
{
|
||||
bool result = false;
|
||||
TypeCode typeCode = Type.GetTypeCode(type);
|
||||
switch (typeCode)
|
||||
{
|
||||
case TypeCode.String:
|
||||
case TypeCode.Char:
|
||||
case TypeCode.SByte:
|
||||
case TypeCode.Byte:
|
||||
case TypeCode.Int16:
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.Int32:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.UInt64:
|
||||
case TypeCode.Single:
|
||||
case TypeCode.Double:
|
||||
case TypeCode.Decimal:
|
||||
case TypeCode.Boolean:
|
||||
case TypeCode.DateTime:
|
||||
result = true;
|
||||
break;
|
||||
|
||||
case TypeCode.Object:
|
||||
if (type == typeof(Point) ||
|
||||
type == typeof(PointF) ||
|
||||
type == typeof(Color) ||
|
||||
type == typeof(Size) ||
|
||||
type == typeof(SizeF))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转对象
|
||||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <param name="type">类型</param>
|
||||
/// <param name="defaultobj">默认对象</param>
|
||||
/// <returns>对象</returns>
|
||||
public static object StringToObject(string str, Type type, object defaultobj)
|
||||
{
|
||||
object obj = defaultobj;
|
||||
|
||||
if (type == typeof(string))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
if (str.IsNullOrEmpty())
|
||||
{
|
||||
return defaultobj;
|
||||
}
|
||||
|
||||
TypeCode typeCode = Type.GetTypeCode(type);
|
||||
switch (typeCode)
|
||||
{
|
||||
case TypeCode.Char:
|
||||
obj = str.ToChar((char)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.SByte:
|
||||
obj = str.ToSByte((sbyte)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
obj = str.ToByte((byte)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Int16:
|
||||
obj = str.ToShort((short)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.UInt16:
|
||||
obj = str.ToUShort((ushort)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Int32:
|
||||
obj = str.ToInt((int)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.UInt32:
|
||||
obj = str.ToUInt((uint)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Int64:
|
||||
obj = str.ToLong((long)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.UInt64:
|
||||
obj = str.ToULong((ulong)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Single:
|
||||
obj = str.ToFloat((float)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Double:
|
||||
obj = str.ToDouble((double)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Decimal:
|
||||
obj = str.ToDecimal((decimal)defaultobj);
|
||||
break;
|
||||
|
||||
case TypeCode.Boolean:
|
||||
if (str.ToUpper().Equals(bool.TrueString.ToUpper()))
|
||||
{
|
||||
obj = true;
|
||||
}
|
||||
|
||||
if (str.ToUpper().Equals(bool.FalseString.ToUpper()))
|
||||
{
|
||||
obj = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TypeCode.DateTime:
|
||||
try
|
||||
{
|
||||
DateTime dt = str.ToDateTime(DateTimeEx.DateTimeFormat);
|
||||
obj = dt;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TypeCode.Object:
|
||||
obj = StringToObjectEx(str, type, defaultobj);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ApplicationException("不支持此类型: " + type.FullName);
|
||||
}
|
||||
|
||||
if (type == typeof(DateTime))
|
||||
{
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串转对象扩展
|
||||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <param name="type">类型</param>
|
||||
/// <param name="defaultobj">默认对象</param>
|
||||
/// <returns>对象</returns>
|
||||
private static object StringToObjectEx(string str, Type type, object defaultobj)
|
||||
{
|
||||
object obj = defaultobj;
|
||||
|
||||
if (type == typeof(Point))
|
||||
{
|
||||
string[] strs = str.ToUpper().Replace("X:", "").Replace("Y:", "").Trim().Split(";");
|
||||
|
||||
if (strs.Length == 2)
|
||||
{
|
||||
if (int.TryParse(strs[0], out var x) && int.TryParse(strs[1], out var y))
|
||||
{
|
||||
obj = new Point(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == typeof(PointF))
|
||||
{
|
||||
string[] strs = str.ToUpper().Replace("X:", "").Replace("Y:", "").Trim().Split(";");
|
||||
|
||||
if (strs.Length == 2)
|
||||
{
|
||||
if (float.TryParse(strs[0], out var x) && float.TryParse(strs[1], out var y))
|
||||
{
|
||||
obj = new PointF(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == typeof(Color))
|
||||
{
|
||||
string[] strs = str.ToUpper().Replace("A:", "").Replace("R:", "").Replace("G:", "").Replace("B:", "").Trim().Split(";");
|
||||
|
||||
if (strs.Length == 4)
|
||||
{
|
||||
if (int.TryParse(strs[0], out var a) && int.TryParse(strs[1], out var r) && int.TryParse(strs[2], out var g) && int.TryParse(strs[3], out var b))
|
||||
{
|
||||
if (a.InRange(0, 255) && r.InRange(0, 255) && g.InRange(0, 255) && b.InRange(0, 255))
|
||||
{
|
||||
obj = Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == typeof(Size))
|
||||
{
|
||||
string[] strs = str.ToUpper().Replace("W:", "").Replace("H:", "").Trim().Split(";");
|
||||
|
||||
if (strs.Length == 2)
|
||||
{
|
||||
if (int.TryParse(strs[0], out var x) && int.TryParse(strs[1], out var y))
|
||||
{
|
||||
obj = new Size(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == typeof(SizeF))
|
||||
{
|
||||
string[] strs = str.ToUpper().Replace("W:", "").Replace("H:", "").Trim().Split(";");
|
||||
|
||||
if (strs.Length == 2)
|
||||
{
|
||||
if (float.TryParse(strs[0], out var x) && float.TryParse(strs[1], out var y))
|
||||
{
|
||||
obj = new SizeF(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ApplicationException("不支持此类型: " + type.FullName);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象转字符串
|
||||
/// </summary>
|
||||
/// <param name="obj">对象</param>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns>字符串</returns>
|
||||
public static string ObjectToString(object obj, Type type)
|
||||
{
|
||||
string value;
|
||||
|
||||
TypeCode typeCode = Type.GetTypeCode(type);
|
||||
switch (typeCode)
|
||||
{
|
||||
case TypeCode.String:
|
||||
if (obj == null)
|
||||
{
|
||||
obj = "";
|
||||
}
|
||||
|
||||
value = obj.ToString();
|
||||
break;
|
||||
|
||||
case TypeCode.Char:
|
||||
case TypeCode.SByte:
|
||||
case TypeCode.Byte:
|
||||
case TypeCode.Int16:
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.Int32:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.UInt64:
|
||||
case TypeCode.Single:
|
||||
case TypeCode.Double:
|
||||
case TypeCode.Decimal:
|
||||
value = obj.ToString();
|
||||
break;
|
||||
|
||||
case TypeCode.Boolean:
|
||||
value = (bool)obj ? bool.TrueString : bool.FalseString;
|
||||
break;
|
||||
|
||||
case TypeCode.DateTime:
|
||||
value = ((DateTime)obj).ToString(DateTimeEx.DateTimeFormat);
|
||||
break;
|
||||
|
||||
case TypeCode.Object:
|
||||
value = ObjectToStringEx(obj, type);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ApplicationException("不支持此类型: " + type.FullName);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象转字符串扩展
|
||||
/// </summary>
|
||||
/// <param name="obj">对象</param>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns>字符串</returns>
|
||||
private static string ObjectToStringEx(object obj, Type type)
|
||||
{
|
||||
string value;
|
||||
|
||||
if (type == typeof(Point))
|
||||
{
|
||||
Point point = (Point)obj;
|
||||
value = "X:" + point.X + "; Y:" + point.Y;
|
||||
}
|
||||
else if (type == typeof(PointF))
|
||||
{
|
||||
PointF point = (PointF)obj;
|
||||
value = "X:" + point.X + "; Y:" + point.Y;
|
||||
}
|
||||
else if (type == typeof(Color))
|
||||
{
|
||||
Color color = (Color)obj;
|
||||
value = "A:" + color.A + "; R:" + color.R + "; G:" + color.G + "; B:" + color.B;
|
||||
}
|
||||
else if (type == typeof(Size))
|
||||
{
|
||||
Size size = (Size)obj;
|
||||
value = "W:" + size.Width + "; H:" + size.Height;
|
||||
}
|
||||
else if (type == typeof(SizeF))
|
||||
{
|
||||
SizeF size = (SizeF)obj;
|
||||
value = "W:" + size.Width + "; H:" + size.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ApplicationException("不支持此类型: " + type.FullName);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
382
SunnyUI/Common/UDateTimeInt64.cs
Normal file
382
SunnyUI/Common/UDateTimeInt64.cs
Normal file
@ -0,0 +1,382 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UDateTimeInt64.cs
|
||||
* 文件说明: 日期长整型
|
||||
* 当前版本: V2.2
|
||||
* 创建日期: 2020-09-23
|
||||
*
|
||||
* 2020-09-23: V2.2.8 增加文件说明
|
||||
* 2020-10-10: V2.2.8 增加与Double互转
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 日期与长整形和浮点型互转
|
||||
/// Value:长整形,为1970年1月1日0时起的毫秒数
|
||||
/// DoubleValue:双精度浮点数,1970年1月1日0时起的天数
|
||||
/// </summary>
|
||||
public struct DateTimeInt64 : IComparable, IEquatable<DateTimeInt64>, IEquatable<long>, IEquatable<DateTime>
|
||||
{
|
||||
public long Value { get; set; }
|
||||
|
||||
public const long Jan1st1970Ticks = 621355968000000000; //Jan1st1970.Ticks;
|
||||
public const long Dec31th9999Ticks = 3155378975999990000; //DateTime.MaxValue.Ticks;
|
||||
public const string DefaultFormatString = DateTimeEx.DateTimeFormatEx;
|
||||
public const double MillisecondsPerDay = 86400000.0;
|
||||
|
||||
/// <summary>
|
||||
/// 返回当前时间的毫秒数, 这个毫秒其实就是自1970年1月1日0时起的毫秒数
|
||||
/// </summary>
|
||||
public static long CurrentDateTimeToTicks()
|
||||
{
|
||||
return (DateTime.UtcNow.Ticks - Jan1st1970Ticks) / 10000;
|
||||
}
|
||||
|
||||
public double DoubleValue
|
||||
{
|
||||
get { return Value * 1.0 / MillisecondsPerDay; }
|
||||
set { Value = (long)(value * MillisecondsPerDay); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回指定时间的毫秒数, 这个毫秒其实就是自1970年1月1日0时起的毫秒数
|
||||
/// </summary>
|
||||
public static long DateTimeToTicks(DateTime datetime)
|
||||
{
|
||||
return (datetime.ToUniversalTime().Ticks - Jan1st1970Ticks) / 10000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从一个代表自1970年1月1日0时起的毫秒数,转换为DateTime (北京时间)
|
||||
/// </summary>
|
||||
public static DateTime TicksToDateTime(long ticks)
|
||||
{
|
||||
#pragma warning disable CS0618 // 类型或成员已过时
|
||||
return TimeZone.CurrentTimeZone.ToLocalTime(TicksToUTCDateTime(ticks));
|
||||
#pragma warning restore CS0618 // 类型或成员已过时
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从一个代表自1970年1月1日0时起的毫秒数,转换为DateTime (UTC时间)
|
||||
/// </summary>
|
||||
public static DateTime TicksToUTCDateTime(long ticks)
|
||||
{
|
||||
return new DateTime(ticks * 10000 + Jan1st1970Ticks);
|
||||
}
|
||||
|
||||
public DateTimeInt64(long ticks)
|
||||
{
|
||||
ticks = MakeValidDate(ticks);
|
||||
Value = ticks;
|
||||
}
|
||||
|
||||
public DateTimeInt64(double doubleTicks)
|
||||
{
|
||||
doubleTicks = MakeValidDate((long)(doubleTicks * MillisecondsPerDay));
|
||||
Value = (long)doubleTicks;
|
||||
}
|
||||
|
||||
public DateTimeInt64(DateTime dateTime)
|
||||
{
|
||||
Value = DateTimeToTicks(dateTime);
|
||||
}
|
||||
|
||||
public DateTimeInt64(int year, int month, int day)
|
||||
{
|
||||
Value = DateTimeToTicks(new DateTime(year, month, day));
|
||||
}
|
||||
|
||||
public DateTimeInt64(int year, int month, int day, int hour, int minute, int second)
|
||||
{
|
||||
Value = DateTimeToTicks(new DateTime(year, month, day, hour, minute, second));
|
||||
}
|
||||
|
||||
public DateTimeInt64(int year, int month, int day, int hour, int minute, int second, int millisecond)
|
||||
{
|
||||
Value = DateTimeToTicks(new DateTime(year, month, day, hour, minute, second, millisecond));
|
||||
}
|
||||
|
||||
public DateTimeInt64(DateTimeInt64 dtValue)
|
||||
{
|
||||
Value = dtValue.Value;
|
||||
}
|
||||
|
||||
public bool IsValidDate
|
||||
{
|
||||
get { return Value >= 0 && Value <= Dec31th9999Ticks - Jan1st1970Ticks; }
|
||||
}
|
||||
|
||||
public DateTime DateTime
|
||||
{
|
||||
get { return TicksToDateTime(Value); }
|
||||
set { Value = DateTimeToTicks(value); }
|
||||
}
|
||||
|
||||
public static bool CheckValidDate(long ticks)
|
||||
{
|
||||
return ticks >= 0 && ticks <= Dec31th9999Ticks - Jan1st1970Ticks;
|
||||
}
|
||||
|
||||
public static long MakeValidDate(long ticks)
|
||||
{
|
||||
if (ticks < 0)
|
||||
ticks = 0;
|
||||
if (ticks > Dec31th9999Ticks - Jan1st1970Ticks)
|
||||
ticks = Dec31th9999Ticks - Jan1st1970Ticks;
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
public void AddMilliseconds(double milliseconds)
|
||||
{
|
||||
Value = DateTimeToTicks(DateTime.AddMilliseconds(milliseconds));
|
||||
}
|
||||
|
||||
public void AddSeconds(double seconds)
|
||||
{
|
||||
Value = DateTimeToTicks(DateTime.AddSeconds(seconds));
|
||||
}
|
||||
|
||||
public void AddMinutes(double minutes)
|
||||
{
|
||||
Value = DateTimeToTicks(DateTime.AddMinutes(minutes));
|
||||
}
|
||||
|
||||
public void AddHours(double hours)
|
||||
{
|
||||
Value = DateTimeToTicks(DateTime.AddHours(hours));
|
||||
}
|
||||
|
||||
public void AddDays(double days)
|
||||
{
|
||||
Value = DateTimeToTicks(DateTime.AddDays(days));
|
||||
}
|
||||
|
||||
public void AddMonths(int months)
|
||||
{
|
||||
Value = DateTimeToTicks(DateTime.AddMonths(months));
|
||||
}
|
||||
|
||||
public void AddYears(int years)
|
||||
{
|
||||
Value = DateTimeToTicks(DateTime.AddYears(years));
|
||||
}
|
||||
|
||||
public static long operator -(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value - dtValue2.Value;
|
||||
}
|
||||
|
||||
public static long operator +(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value + dtValue2.Value;
|
||||
}
|
||||
|
||||
public static DateTimeInt64 operator -(DateTimeInt64 dtValue1, long dtValue2)
|
||||
{
|
||||
dtValue1.Value -= dtValue2;
|
||||
return dtValue1;
|
||||
}
|
||||
|
||||
public static DateTimeInt64 operator +(DateTimeInt64 dtValue1, long dtValue2)
|
||||
{
|
||||
dtValue1.Value += dtValue2;
|
||||
return dtValue1;
|
||||
}
|
||||
|
||||
public static DateTimeInt64 operator ++(DateTimeInt64 dtValue)
|
||||
{
|
||||
dtValue.AddDays(1);
|
||||
return dtValue;
|
||||
}
|
||||
|
||||
public static DateTimeInt64 operator --(DateTimeInt64 dtValue)
|
||||
{
|
||||
dtValue.AddDays(-1);
|
||||
return dtValue;
|
||||
}
|
||||
|
||||
public static implicit operator long(DateTimeInt64 dtValue)
|
||||
{
|
||||
return dtValue.Value;
|
||||
}
|
||||
|
||||
public static implicit operator DateTimeInt64(long ticks)
|
||||
{
|
||||
return new DateTimeInt64(ticks);
|
||||
}
|
||||
|
||||
public static implicit operator DateTimeInt64(DateTime dt)
|
||||
{
|
||||
return new DateTimeInt64(dt);
|
||||
}
|
||||
|
||||
public static implicit operator DateTime(DateTimeInt64 dt)
|
||||
{
|
||||
return dt.DateTime;
|
||||
}
|
||||
|
||||
public static implicit operator double(DateTimeInt64 dtValue)
|
||||
{
|
||||
return dtValue.DoubleValue;
|
||||
}
|
||||
|
||||
public static implicit operator DateTimeInt64(double ticks)
|
||||
{
|
||||
return new DateTimeInt64(ticks);
|
||||
}
|
||||
|
||||
public static bool operator ==(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value == dtValue2.Value;
|
||||
}
|
||||
|
||||
public static bool operator !=(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value != dtValue2.Value;
|
||||
}
|
||||
|
||||
public static bool operator ==(DateTimeInt64 dtValue, long ticks)
|
||||
{
|
||||
return dtValue.Value == ticks;
|
||||
}
|
||||
|
||||
public static bool operator !=(DateTimeInt64 dtValue, long ticks)
|
||||
{
|
||||
return dtValue.Value != ticks;
|
||||
}
|
||||
|
||||
public static bool operator <(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value < dtValue2.Value;
|
||||
}
|
||||
|
||||
public static bool operator >(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value > dtValue2.Value;
|
||||
}
|
||||
|
||||
public static bool operator <=(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value <= dtValue2.Value;
|
||||
}
|
||||
|
||||
public static bool operator >=(DateTimeInt64 dtValue1, DateTimeInt64 dtValue2)
|
||||
{
|
||||
return dtValue1.Value >= dtValue2.Value;
|
||||
}
|
||||
|
||||
public static bool operator <(DateTimeInt64 dtValue, long ticks)
|
||||
{
|
||||
return dtValue.Value < ticks;
|
||||
}
|
||||
|
||||
public static bool operator >(DateTimeInt64 dtValue, long ticks)
|
||||
{
|
||||
return dtValue.Value > ticks;
|
||||
}
|
||||
|
||||
public static bool operator <=(DateTimeInt64 dtValue, long ticks)
|
||||
{
|
||||
return dtValue.Value <= ticks;
|
||||
}
|
||||
|
||||
public static bool operator >=(DateTimeInt64 dtValue, long ticks)
|
||||
{
|
||||
return dtValue.Value >= ticks;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is DateTimeInt64 dtValue)
|
||||
{
|
||||
return dtValue.Value == Value;
|
||||
}
|
||||
else if (obj is long longValue)
|
||||
{
|
||||
return longValue == Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
int IComparable.CompareTo(object obj)
|
||||
{
|
||||
if (!(obj is DateTimeInt64)) throw new ArgumentException();
|
||||
return (Value).CompareTo(((DateTimeInt64)obj).Value);
|
||||
}
|
||||
|
||||
public string ToString(long ticks)
|
||||
{
|
||||
return ToString(ticks, DefaultFormatString);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToString(Value, DefaultFormatString);
|
||||
}
|
||||
|
||||
public string ToString(string fmtStr)
|
||||
{
|
||||
return ToString(Value, fmtStr);
|
||||
}
|
||||
|
||||
public static string ToString(long dtValue, string fmtStr)
|
||||
{
|
||||
DateTime dt = TicksToDateTime(dtValue);
|
||||
return dt.ToString(fmtStr);
|
||||
}
|
||||
|
||||
public bool Equals(DateTimeInt64 dtValue)
|
||||
{
|
||||
return Value == dtValue.Value;
|
||||
}
|
||||
|
||||
public bool Equals(long ticks)
|
||||
{
|
||||
return Value == ticks;
|
||||
}
|
||||
|
||||
public bool Equals(DateTime datetime)
|
||||
{
|
||||
return Value == (new DateTimeInt64(datetime)).Value;
|
||||
}
|
||||
|
||||
public string DateTimeString => DateTime.DateTimeString();
|
||||
|
||||
public string DateString => DateTime.DateString();
|
||||
|
||||
public string TimeString => DateTime.TimeString();
|
||||
|
||||
public string HourMinuteString => DateTime.ToString("HH:mm");
|
||||
|
||||
public int Year => DateTime.Year;
|
||||
public int Month => DateTime.Month;
|
||||
public int Day => DateTime.Day;
|
||||
public int Hour => DateTime.Hour;
|
||||
public int Minute => DateTime.Minute;
|
||||
public int Second => DateTime.Second;
|
||||
public int Millisecond => DateTime.Millisecond;
|
||||
}
|
||||
}
|
@ -22,7 +22,6 @@
|
||||
* 2023-08-11: v3.4.1 增加了文件绝对路径判断和文件夹是否存在判断
|
||||
******************************************************************************/
|
||||
|
||||
using Sunny.UI.Win32;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
@ -31,6 +30,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Sunny.UI.Win32;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
@ -299,29 +299,6 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
public class IniFile : IniBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 写Byte数组
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, byte[] value)
|
||||
{
|
||||
Write(section, key, value.ToHexString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Byte数组
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public byte[] ReadBytes(string section, string key, byte[] Default)
|
||||
{
|
||||
return Read(section, key, Default.ToHexString()).ToHexBytes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Char
|
||||
/// </summary>
|
||||
|
790
SunnyUI/Common/UIniFileEx.cs
Normal file
790
SunnyUI/Common/UIniFileEx.cs
Normal file
@ -0,0 +1,790 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UIniFileEx.cs
|
||||
* 文件说明: INI 文件读取类(不用WinAPI)
|
||||
* 当前版本: V3.1
|
||||
* 创建日期: 2021-10-27
|
||||
*
|
||||
* 2021-10-27: V2.2.0 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
public class IniFileEx
|
||||
{
|
||||
private readonly Dictionary<string, NameValueCollection> data = new Dictionary<string, NameValueCollection>();
|
||||
|
||||
private static readonly Regex regRemoveEmptyLines =
|
||||
new Regex
|
||||
(
|
||||
@"(\s*;[\d\D]*?\r?\n)+|\r?\n(\s*\r?\n)*",
|
||||
RegexOptions.Multiline | RegexOptions.Compiled
|
||||
);
|
||||
|
||||
private static readonly Regex regParseIniData =
|
||||
new Regex
|
||||
(
|
||||
@"
|
||||
(?<IsSection>
|
||||
^\s*\[(?<SectionName>[^\]]+)?\]\s*$
|
||||
)
|
||||
|
|
||||
(?<IsKeyValue>
|
||||
^\s*(?<Key>[^(\s*\=\s*)]+)?\s*\=\s*(?<Value>[\d\D]*)$
|
||||
)",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace
|
||||
);
|
||||
|
||||
public IniFileEx(string fileName) : this(fileName, Encoding.Default) { }
|
||||
|
||||
public IniFileEx(string fileName, Encoding encoding)
|
||||
{
|
||||
FileName = fileName;
|
||||
Encoding = encoding;
|
||||
using FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
|
||||
ReadIniData(fs, encoding);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件名
|
||||
/// </summary>
|
||||
[Description("文件名")]
|
||||
public string FileName { get; set; } //INI文件名
|
||||
|
||||
public Encoding Encoding { get; set; }
|
||||
|
||||
private void ReadIniData(Stream stream, Encoding encoding)
|
||||
{
|
||||
string lastSection = string.Empty;
|
||||
data.Add(lastSection, new NameValueCollection());
|
||||
if (stream != null && encoding != null)
|
||||
{
|
||||
using StreamReader reader = new StreamReader(stream, encoding);
|
||||
string iniData = reader.ReadToEnd();
|
||||
|
||||
iniData = regRemoveEmptyLines.Replace(iniData, "\n");
|
||||
string[] lines = iniData.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string s in lines)
|
||||
{
|
||||
Match m = regParseIniData.Match(s);
|
||||
if (m.Success)
|
||||
{
|
||||
if (m.Groups["IsSection"].Length > 0)
|
||||
{
|
||||
string sName = m.Groups["SectionName"].Value.ToLowerInvariant();
|
||||
if (lastSection != sName)
|
||||
{
|
||||
lastSection = sName;
|
||||
if (!data.ContainsKey(sName))
|
||||
{
|
||||
data.Add(sName, new NameValueCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m.Groups["IsKeyValue"].Length > 0)
|
||||
{
|
||||
data[lastSection].Add(m.Groups["Key"].Value, m.Groups["Value"].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NameValueCollection this[string section]
|
||||
{
|
||||
get
|
||||
{
|
||||
section = section.ToLowerInvariant();
|
||||
if (!data.ContainsKey(section))
|
||||
data.Add(section, new NameValueCollection());
|
||||
return data[section];
|
||||
}
|
||||
}
|
||||
|
||||
public string this[string section, string key]
|
||||
{
|
||||
get => this[section][key];
|
||||
set => this[section][key] = value;
|
||||
}
|
||||
|
||||
public object this[string section, string key, Type t]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (t == null || t == (Type)Type.Missing)
|
||||
return this[section][key];
|
||||
return GetValue(section, key, null, t);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (t == null || t == (Type)Type.Missing)
|
||||
this[section][key] = string.Empty;
|
||||
else
|
||||
SetValue(section, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public string[] KeyNames(string section)
|
||||
{
|
||||
return this[section].AllKeys;
|
||||
}
|
||||
|
||||
public string[] SectionValues(string section)
|
||||
{
|
||||
return this[section].GetValues(0);
|
||||
}
|
||||
|
||||
private object GetValue(string section, string key, object defaultValue, Type t)
|
||||
{
|
||||
section = section.ToLowerInvariant();
|
||||
key = key.ToLowerInvariant();
|
||||
if (!data.ContainsKey(section)) return defaultValue;
|
||||
string v = data[section][key];
|
||||
if (string.IsNullOrEmpty(v)) return defaultValue;
|
||||
TypeConverter conv = TypeDescriptor.GetConverter(t);
|
||||
if (!conv.CanConvertFrom(typeof(string))) return defaultValue;
|
||||
|
||||
try
|
||||
{
|
||||
return conv.ConvertFrom(v);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
private T GetValue<T>(string section, string key, T defaultValue)
|
||||
{
|
||||
return (T)GetValue(section, key, defaultValue, typeof(T));
|
||||
}
|
||||
|
||||
private void SetValue(string section, string key, object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
this[section][key] = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
TypeConverter conv = TypeDescriptor.GetConverter(value);
|
||||
if (!conv.CanConvertTo(typeof(string)))
|
||||
{
|
||||
this[section][key] = value.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
this[section][key] = (string)conv.ConvertTo(value, typeof(string));
|
||||
}
|
||||
}
|
||||
|
||||
UpdateFile();
|
||||
}
|
||||
|
||||
public void Write(string section, string key, string value)
|
||||
{
|
||||
SetValue(section, key, value);
|
||||
}
|
||||
|
||||
public string Read(string section, string key, string Default)
|
||||
{
|
||||
return GetValue(section, key, Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取指定的Section的所有Value到列表中
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
public NameValueCollection GetSectionValues(string section)
|
||||
{
|
||||
return this[section];
|
||||
}
|
||||
|
||||
public void UpdateFile()
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
Save(FileName, Encoding);
|
||||
}
|
||||
|
||||
public void Save(string fileName, Encoding encoding)
|
||||
{
|
||||
using FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
|
||||
Save(fs, encoding);
|
||||
}
|
||||
|
||||
private void Save(Stream stream, Encoding encoding)
|
||||
{
|
||||
using StreamWriter sw = new StreamWriter(stream, encoding);
|
||||
foreach (var cur in data)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(cur.Key))
|
||||
{
|
||||
sw.WriteLine("[{0}]", cur.Key);
|
||||
}
|
||||
|
||||
NameValueCollection col = cur.Value;
|
||||
foreach (string key in col.Keys)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
string value = col[key];
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
sw.WriteLine("{0}={1}", key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sw.Flush();
|
||||
}
|
||||
|
||||
public bool HasSection(string section)
|
||||
{
|
||||
return data.ContainsKey(section.ToLowerInvariant());
|
||||
}
|
||||
|
||||
public bool HasKey(string section, string key)
|
||||
{
|
||||
return
|
||||
data.ContainsKey(section) &&
|
||||
!string.IsNullOrEmpty(data[section][key]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写结构
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
/// <typeparam name="T">T</typeparam>
|
||||
public void WriteStruct<T>(string section, string key, T value) where T : struct
|
||||
{
|
||||
Write(section, key, value.ToBytes());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读结构
|
||||
/// </summary>
|
||||
/// <typeparam name="T">T</typeparam>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public T ReadStruct<T>(string section, string key, T Default) where T : struct
|
||||
{
|
||||
//得到结构体的大小
|
||||
int size = StructEx.Size(Default);
|
||||
byte[] bytes = Read(section, key, "").ToHexBytes();
|
||||
return size > bytes.Length ? Default : bytes.ToStruct<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Byte数组
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, byte[] value)
|
||||
{
|
||||
Write(section, key, value.ToHexString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Byte数组
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public byte[] ReadBytes(string section, string key, byte[] Default)
|
||||
{
|
||||
return Read(section, key, Default.ToHexString()).ToHexBytes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Char
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, char value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Char
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public char ReadChar(string section, string key, char Default = ' ')
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToChar(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Decimal
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, decimal value)
|
||||
{
|
||||
Write(section, key, value.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Decimal
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public decimal ReadDecimal(string section, string key, decimal Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString(CultureInfo.InvariantCulture)).ToDecimal(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, short value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public short ReadShort(string section, string key, short Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToShort(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, ushort value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public ushort ReadUShort(string section, string key, ushort Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToUShort(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, int value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public int ReadInt(string section, string key, int Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToInt(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, uint value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public uint ReadUInt(string section, string key, uint Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToUInt(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, ulong value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public ulong ReadULong(string section, string key, ulong Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToULong(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, long value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读整数
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public long ReadLong(string section, string key, long Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToLong(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写布尔
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, bool value)
|
||||
{
|
||||
Write(section, key, value ? bool.TrueString : bool.FalseString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读布尔
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public bool ReadBool(string section, string key, bool Default = false)
|
||||
{
|
||||
string str = Read(section, key, Default.ToString());
|
||||
if (string.Equals(str, bool.TrueString, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (string.Equals(str, bool.FalseString, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Double
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, double value)
|
||||
{
|
||||
Write(section, key, value.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Double
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public double ReadDouble(string section, string key, double Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString(CultureInfo.InvariantCulture)).ToDouble(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Float
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, float value)
|
||||
{
|
||||
Write(section, key, value.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Float
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public float ReadFloat(string section, string key, float Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString(CultureInfo.InvariantCulture)).ToFloat(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Byte
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, byte value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Byte
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public byte ReadByte(string section, string key, byte Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToByte(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写SByte
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, sbyte value)
|
||||
{
|
||||
Write(section, key, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Byte
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public sbyte ReadSByte(string section, string key, sbyte Default = 0)
|
||||
{
|
||||
return Read(section, key, Default.ToString()).ToSByte(Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写DateTime
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, DateTime value)
|
||||
{
|
||||
Write(section, key, value.ToString(DateTimeEx.DateTimeFormat));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读DateTime
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public DateTime ReadDateTime(string section, string key, DateTime Default)
|
||||
{
|
||||
string str = Read(section, key, Default.ToString(CultureInfo.InvariantCulture));
|
||||
try
|
||||
{
|
||||
return str.ToDateTime(DateTimeEx.DateTimeFormat);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Point
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, Point value)
|
||||
{
|
||||
Write(section, key, ConvertEx.ObjectToString(value, typeof(Point)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Point
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public Point ReadPoint(string section, string key, Point Default)
|
||||
{
|
||||
string str = Read(section, key, "");
|
||||
return (Point)ConvertEx.StringToObject(str, typeof(Point), Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写PointF
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, PointF value)
|
||||
{
|
||||
Write(section, key, ConvertEx.ObjectToString(value, typeof(PointF)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读PointF
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public PointF ReadPointF(string section, string key, PointF Default)
|
||||
{
|
||||
string str = Read(section, key, "");
|
||||
return (PointF)ConvertEx.StringToObject(str, typeof(PointF), Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Size
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, Size value)
|
||||
{
|
||||
Write(section, key, ConvertEx.ObjectToString(value, typeof(Size)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Size
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public Size ReadSize(string section, string key, Size Default)
|
||||
{
|
||||
string str = Read(section, key, "");
|
||||
return (Size)ConvertEx.StringToObject(str, typeof(Size), Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写SizeF
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, SizeF value)
|
||||
{
|
||||
Write(section, key, ConvertEx.ObjectToString(value, typeof(SizeF)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读SizeF
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public SizeF ReadSizeF(string section, string key, SizeF Default)
|
||||
{
|
||||
string str = Read(section, key, "");
|
||||
return (SizeF)ConvertEx.StringToObject(str, typeof(SizeF), Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写Color
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">value</param>
|
||||
public void Write(string section, string key, Color value)
|
||||
{
|
||||
Write(section, key, ConvertEx.ObjectToString(value, typeof(Color)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读Color
|
||||
/// </summary>
|
||||
/// <param name="section">section</param>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="Default">Normal</param>
|
||||
/// <returns>结果</returns>
|
||||
public Color ReadColor(string section, string key, Color Default)
|
||||
{
|
||||
string str = Read(section, key, "");
|
||||
return (Color)ConvertEx.StringToObject(str, typeof(Color), Default);
|
||||
}
|
||||
}
|
||||
}
|
203
SunnyUI/Common/UMapper.cs
Normal file
203
SunnyUI/Common/UMapper.cs
Normal file
@ -0,0 +1,203 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UMapper.cs
|
||||
* 文件说明: 轻量级的对象映射框架,可以映射值类型(包括Struct),和以值类型构成的List和数组。
|
||||
* 当前版本: V3.1
|
||||
* 创建日期: 2021-09-30
|
||||
*
|
||||
* 2021-09-30: V3.0.7 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 轻量级的对象映射框架
|
||||
/// </summary>
|
||||
public static class Mapper
|
||||
{
|
||||
private static void Execute<T1, T2>(T1 source, T2 dest)
|
||||
where T1 : class, new()
|
||||
where T2 : class, new()
|
||||
{
|
||||
if (source == null || dest == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var listSource = source.GetType().GetNeedProperties().ToDictionary(prop => prop.Name);
|
||||
var listDest = dest.GetType().GetNeedProperties().ToDictionary(prop => prop.Name);
|
||||
|
||||
foreach (var item in listDest)
|
||||
{
|
||||
if (listSource.NotContainsKey(item.Key)) continue;
|
||||
|
||||
var sourceInfo = listSource[item.Key];
|
||||
Type sourceType = sourceInfo.PropertyType;
|
||||
object sourceValue = sourceInfo.GetValue(source, null);
|
||||
|
||||
var destInfo = item.Value;
|
||||
Type destType = item.Value.PropertyType;
|
||||
|
||||
if (!sourceType.Equals(destType)) continue;
|
||||
if (sourceType.IsValueType)
|
||||
{
|
||||
//Console.WriteLine("ValueType: " + item.Key + ", " + sourceType.FullName);
|
||||
destInfo.SetValue(dest, sourceValue, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
{
|
||||
//Console.WriteLine("String: " + item.Key + ", " + sourceType.FullName);
|
||||
destInfo.SetValue(dest, sourceValue, null);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sourceType.IsList())
|
||||
{
|
||||
//Console.WriteLine("List: " + item.Key + ", " + sourceType.FullName);
|
||||
Type[] sourceTypes = sourceType.GetGenericArguments();
|
||||
Type[] destTypes = destType.GetGenericArguments();
|
||||
if (sourceTypes.Length != 1) continue;
|
||||
if (destTypes.Length != 1) continue;
|
||||
if (!sourceTypes[0].Equals(destTypes[0])) continue;
|
||||
|
||||
if (sourceValue == null)
|
||||
{
|
||||
destInfo.SetValue(dest, null, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type typeDataList = typeof(List<>).MakeGenericType(destTypes[0]);
|
||||
MethodInfo AddInfo = typeDataList.GetMethod("Add", BindingFlags.Public | BindingFlags.Instance);
|
||||
if (AddInfo == null) continue;
|
||||
|
||||
if (sourceTypes[0].IsValueType || sourceTypes[0] == typeof(string))
|
||||
{
|
||||
object listvalue = typeDataList.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, new object[] { });
|
||||
IEnumerable sourceList = sourceValue as IEnumerable;
|
||||
foreach (var listItem in sourceList)
|
||||
{
|
||||
AddInfo.Invoke(listvalue, new[] { listItem });
|
||||
}
|
||||
|
||||
destInfo.SetValue(dest, listvalue, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
//暂时不考虑
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sourceType.IsArray)
|
||||
{
|
||||
//Console.WriteLine("Array: " + item.Key + ", " + sourceType.FullName);
|
||||
if (sourceValue == null)
|
||||
{
|
||||
destInfo.SetValue(dest, null, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
ICollection sourceList = sourceValue as ICollection;
|
||||
Type type = sourceType.GetElementType();
|
||||
var array = Array.CreateInstance(type, sourceList.Count);
|
||||
|
||||
int index = 0;
|
||||
foreach (var listItem in sourceList)
|
||||
{
|
||||
array.SetValue(listItem, index++);
|
||||
}
|
||||
|
||||
destInfo.SetValue(dest, array, null);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sourceType.IsDictionary())
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//类没有无参构造函数的话,创建有问题
|
||||
//if (sourceType.IsClass)
|
||||
//{
|
||||
// if (sourceValue == null)
|
||||
// {
|
||||
// destInfo.SetValue(dest, null, null);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// object obj = Activator.CreateInstance(sourceType, null);
|
||||
// obj.MapperFrom(sourceValue);
|
||||
// destInfo.SetValue(dest, obj, null);
|
||||
// }
|
||||
//
|
||||
// continue;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// T1映射到T2
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">T1</typeparam>
|
||||
/// <typeparam name="T2">T2</typeparam>
|
||||
/// <param name="source">源</param>
|
||||
/// <param name="dest">目标</param>
|
||||
public static void MapperTo<T1, T2>(this T1 source, T2 dest)
|
||||
where T1 : class, new()
|
||||
where T2 : class, new()
|
||||
{
|
||||
Execute(source, dest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// T1从T2映射
|
||||
/// </summary>
|
||||
/// <typeparam name="T1">T1</typeparam>
|
||||
/// <typeparam name="T2">T2</typeparam>
|
||||
/// <param name="source">源</param>
|
||||
/// <param name="dest">目标</param>
|
||||
public static void MapperFrom<T1, T2>(this T1 dest, T2 source)
|
||||
where T1 : class, new()
|
||||
where T2 : class, new()
|
||||
{
|
||||
Execute(source, dest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数组的类类型
|
||||
/// </summary>
|
||||
/// <param name="t">类型</param>
|
||||
/// <returns>类类型</returns>
|
||||
public static Type GetArrayElementType(this Type t)
|
||||
{
|
||||
if (!t.IsArray) return null;
|
||||
string name = t.FullName.Replace("[]", string.Empty);
|
||||
return t.Assembly.GetType(name);
|
||||
}
|
||||
}
|
||||
}
|
@ -22,9 +22,9 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#pragma warning disable 1591
|
||||
|
||||
@ -32,7 +32,7 @@ namespace Sunny.UI
|
||||
{
|
||||
public class Thunder : IDisposable
|
||||
{
|
||||
private readonly Timer timer;
|
||||
private readonly System.Windows.Forms.Timer timer;
|
||||
private bool Exit;
|
||||
|
||||
public delegate void OnTaskInfoChange(object sender, ThunderTask task);
|
||||
@ -52,7 +52,7 @@ namespace Sunny.UI
|
||||
public Thunder()
|
||||
{
|
||||
InitSuccess = ThunderDll.Init();
|
||||
timer = new Timer();
|
||||
timer = new System.Windows.Forms.Timer();
|
||||
timer.Interval = 1000;
|
||||
timer.Tick += Timer_Tick;
|
||||
timer.Start();
|
||||
@ -512,7 +512,7 @@ namespace Sunny.UI
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Status.DisplayText() + ",已完成:" + (Percent * 100.0f).ToString("F2") + "%,速度:" + Speed + "KB/s";
|
||||
return Status.Description() + ",已完成:" + (Percent * 100.0f).ToString("F2") + "%,速度:" + Speed + "KB/s";
|
||||
}
|
||||
}
|
||||
|
||||
@ -524,43 +524,43 @@ namespace Sunny.UI
|
||||
/// <summary>
|
||||
/// 无
|
||||
/// </summary>
|
||||
[DisplayText("无")]
|
||||
[Description("无")]
|
||||
NOITEM = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 错误
|
||||
/// </summary>
|
||||
[DisplayText("错误")]
|
||||
[Description("错误")]
|
||||
TSC_ERROR,
|
||||
|
||||
/// <summary>
|
||||
/// 暂停
|
||||
/// </summary>
|
||||
[DisplayText("暂停")]
|
||||
[Description("暂停")]
|
||||
TSC_PAUSE,
|
||||
|
||||
/// <summary>
|
||||
/// 下载
|
||||
/// </summary>
|
||||
[DisplayText("下载中")]
|
||||
[Description("下载中")]
|
||||
TSC_DOWNLOAD,
|
||||
|
||||
/// <summary>
|
||||
/// 完成
|
||||
/// </summary>
|
||||
[DisplayText("完成")]
|
||||
[Description("完成")]
|
||||
TSC_COMPLETE,
|
||||
|
||||
/// <summary>
|
||||
/// 停止开始
|
||||
/// </summary>
|
||||
[DisplayText("已开始")]
|
||||
[Description("已开始")]
|
||||
TSC_STARTENDING,
|
||||
|
||||
/// <summary>
|
||||
/// 停止完成
|
||||
/// </summary>
|
||||
[DisplayText("已停止")]
|
||||
[Description("已停止")]
|
||||
TSC_STOPENDING
|
||||
}
|
||||
|
||||
|
163
SunnyUI/Common/UXmlConfig.cs
Normal file
163
SunnyUI/Common/UXmlConfig.cs
Normal file
@ -0,0 +1,163 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.Common.dll can be used for free under the MIT license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UXmlConfig.cs
|
||||
* 文件说明: XML 配置文件类
|
||||
* 当前版本: V3.1
|
||||
* 创建日期: 2020-01-01
|
||||
*
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// XML 配置文件类
|
||||
/// </summary>
|
||||
/// <typeparam name="TConfig">类型</typeparam>
|
||||
public class XmlConfig<TConfig> : BaseConfig<TConfig> where TConfig : XmlConfig<TConfig>, new()
|
||||
{
|
||||
#region 加载
|
||||
/// <summary>
|
||||
/// 当前可执行文件路径,末尾包括\
|
||||
/// </summary>
|
||||
/// <returns>结果</returns>
|
||||
private static string CurrentDir()
|
||||
{
|
||||
return Environment.CurrentDirectory.DealPath();
|
||||
}
|
||||
|
||||
/// <summary>加载指定配置文件</summary>
|
||||
/// <param name="filename">文件名</param>
|
||||
/// <returns>结果</returns>
|
||||
public override bool Load(string filename)
|
||||
{
|
||||
if (filename.IsNullOrWhiteSpace())
|
||||
{
|
||||
filename = CurrentDir() + ConfigFile;
|
||||
}
|
||||
|
||||
if (filename.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw new ApplicationException($"未指定{typeof(TConfig).Name}的配置文件路径!");
|
||||
}
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ConcurrentDictionary<string, Ident> idents = ConfigHelper.InitIdents(current);
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(filename);
|
||||
XmlElement root = doc.DocumentElement; //获取根节点
|
||||
foreach (Ident ident in idents.Values)
|
||||
{
|
||||
if (root != null)
|
||||
{
|
||||
var elements = root.GetElementsByTagName(ident.Key);
|
||||
if (elements.Count == 1)
|
||||
{
|
||||
if (ident.IsList)
|
||||
{
|
||||
ident.Values.Clear();
|
||||
foreach (XmlNode node in elements[0].ChildNodes)
|
||||
{
|
||||
ident.Values.Add(node.InnerText);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ident.Value = elements[0].InnerText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigHelper.LoadConfigValue(current, idents);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>保存到配置文件中去</summary>
|
||||
/// <param name="filename">文件名</param>
|
||||
public override void Save(string filename)
|
||||
{
|
||||
if (filename.IsNullOrWhiteSpace())
|
||||
{
|
||||
filename = CurrentDir() + ConfigFile;
|
||||
}
|
||||
|
||||
if (filename.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw new ApplicationException($"未指定{typeof(TConfig).Name}的配置文件路径!");
|
||||
}
|
||||
|
||||
ConcurrentDictionary<string, Ident> idents = ConfigHelper.InitIdents(current);
|
||||
ConfigHelper.SaveConfigValue(Current, idents);
|
||||
|
||||
List<string> strs = new List<string> { "<?xml version=" + "\"" + "1.0" + "\"" + " encoding=" + "\"" + "utf-8" + "\"" + "?> ", "<!--" + Description + "--> " };
|
||||
|
||||
strs.Add("<" + GetType().Name + ">");
|
||||
|
||||
SortedList<int, Ident> slist = new SortedList<int, Ident>();
|
||||
foreach (var ident in idents.Values)
|
||||
{
|
||||
slist.Add(ident.Index, ident);
|
||||
}
|
||||
|
||||
foreach (var ident in slist.Values)
|
||||
{
|
||||
if (!ident.Description.IsNullOrEmpty())
|
||||
{
|
||||
strs.Add(" <!--" + ident.Description + "-->");
|
||||
}
|
||||
|
||||
if (!ident.IsList)
|
||||
{
|
||||
strs.Add(" <" + ident.Key + ">" + ident.Value + "</" + ident.Key + ">");
|
||||
}
|
||||
else
|
||||
{
|
||||
strs.Add(" <" + ident.Key + ">");
|
||||
foreach (string value in ident.Values)
|
||||
{
|
||||
strs.Add(" <Value>" + value + "</Value>");
|
||||
}
|
||||
|
||||
strs.Add(" </" + ident.Key + ">");
|
||||
}
|
||||
}
|
||||
|
||||
strs.Add("</" + GetType().Name + ">");
|
||||
File.WriteAllLines(filename, strs.ToArray(), Encoding.UTF8);
|
||||
}
|
||||
|
||||
#endregion 加载
|
||||
}
|
||||
}
|
@ -456,6 +456,7 @@ namespace Sunny.UI
|
||||
btnOK.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
|
||||
btnOK.Size = new Size(95, 26);
|
||||
btnOK.Style = UIStyle.Custom;
|
||||
btnOK.SymbolOffset = new Point(0, 1);
|
||||
btnOK.TabIndex = 12;
|
||||
btnOK.Text = "确定";
|
||||
btnOK.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
@ -471,7 +472,8 @@ namespace Sunny.UI
|
||||
btnCancel.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
|
||||
btnCancel.Size = new Size(95, 26);
|
||||
btnCancel.Style = UIStyle.Custom;
|
||||
btnCancel.Symbol = 61453;
|
||||
btnCancel.Symbol = 361453;
|
||||
btnCancel.SymbolOffset = new Point(0, 1);
|
||||
btnCancel.TabIndex = 13;
|
||||
btnCancel.Text = "取消";
|
||||
btnCancel.TipsFont = new Font("宋体", 9F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/******************************************************************************
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2025 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
@ -102,11 +102,11 @@ namespace Sunny.UI
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle11 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle12 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle13 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle14 = new DataGridViewCellStyle();
|
||||
DataGridViewCellStyle dataGridViewCellStyle15 = new DataGridViewCellStyle();
|
||||
panel = new UIPanel();
|
||||
btnCancel = new UISymbolButton();
|
||||
btnOK = new UISymbolButton();
|
||||
@ -159,9 +159,11 @@ namespace Sunny.UI
|
||||
btnCancel.Size = new System.Drawing.Size(80, 29);
|
||||
btnCancel.Style = UIStyle.Custom;
|
||||
btnCancel.StyleCustomMode = true;
|
||||
btnCancel.Symbol = 61453;
|
||||
btnCancel.Symbol = 361453;
|
||||
btnCancel.SymbolOffset = new System.Drawing.Point(0, 1);
|
||||
btnCancel.TabIndex = 1;
|
||||
btnCancel.Text = "取消";
|
||||
btnCancel.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnCancel.Click += btnCancel_Click;
|
||||
//
|
||||
// btnOK
|
||||
@ -173,33 +175,35 @@ namespace Sunny.UI
|
||||
btnOK.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
btnOK.Name = "btnOK";
|
||||
btnOK.Size = new System.Drawing.Size(80, 29);
|
||||
btnOK.SymbolOffset = new System.Drawing.Point(0, 1);
|
||||
btnOK.TabIndex = 0;
|
||||
btnOK.Text = "确定";
|
||||
btnOK.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnOK.Click += btnOK_Click;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(243, 249, 255);
|
||||
dataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
|
||||
dataGridViewCellStyle11.BackColor = System.Drawing.Color.FromArgb(243, 249, 255);
|
||||
dataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle11;
|
||||
dataGridView.BackgroundColor = System.Drawing.Color.FromArgb(243, 249, 255);
|
||||
dataGridView.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
|
||||
dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||||
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(80, 160, 255);
|
||||
dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 12F);
|
||||
dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
|
||||
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.FromArgb(80, 160, 255);
|
||||
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||
dataGridViewCellStyle2.WrapMode = DataGridViewTriState.True;
|
||||
dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
|
||||
dataGridViewCellStyle12.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
||||
dataGridViewCellStyle12.BackColor = System.Drawing.Color.FromArgb(80, 160, 255);
|
||||
dataGridViewCellStyle12.Font = new System.Drawing.Font("宋体", 12F);
|
||||
dataGridViewCellStyle12.ForeColor = System.Drawing.Color.White;
|
||||
dataGridViewCellStyle12.SelectionBackColor = System.Drawing.Color.FromArgb(80, 160, 255);
|
||||
dataGridViewCellStyle12.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
|
||||
dataGridViewCellStyle12.WrapMode = DataGridViewTriState.True;
|
||||
dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle12;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft;
|
||||
dataGridViewCellStyle3.BackColor = System.Drawing.Color.White;
|
||||
dataGridViewCellStyle3.Font = new System.Drawing.Font("宋体", 12F);
|
||||
dataGridViewCellStyle3.ForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.Color.FromArgb(220, 236, 255);
|
||||
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle3.WrapMode = DataGridViewTriState.False;
|
||||
dataGridView.DefaultCellStyle = dataGridViewCellStyle3;
|
||||
dataGridViewCellStyle13.Alignment = DataGridViewContentAlignment.MiddleLeft;
|
||||
dataGridViewCellStyle13.BackColor = System.Drawing.Color.White;
|
||||
dataGridViewCellStyle13.Font = new System.Drawing.Font("宋体", 12F);
|
||||
dataGridViewCellStyle13.ForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle13.SelectionBackColor = System.Drawing.Color.FromArgb(220, 236, 255);
|
||||
dataGridViewCellStyle13.SelectionForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle13.WrapMode = DataGridViewTriState.False;
|
||||
dataGridView.DefaultCellStyle = dataGridViewCellStyle13;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.EnableHeadersVisualStyles = false;
|
||||
dataGridView.Font = new System.Drawing.Font("宋体", 12F);
|
||||
@ -207,19 +211,19 @@ namespace Sunny.UI
|
||||
dataGridView.Location = new System.Drawing.Point(0, 44);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleLeft;
|
||||
dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(243, 249, 255);
|
||||
dataGridViewCellStyle4.Font = new System.Drawing.Font("宋体", 12F);
|
||||
dataGridViewCellStyle4.ForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.Color.FromArgb(80, 160, 255);
|
||||
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle4.WrapMode = DataGridViewTriState.True;
|
||||
dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
|
||||
dataGridViewCellStyle5.BackColor = System.Drawing.Color.White;
|
||||
dataGridViewCellStyle5.ForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.FromArgb(220, 236, 255);
|
||||
dataGridViewCellStyle5.SelectionForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridView.RowsDefaultCellStyle = dataGridViewCellStyle5;
|
||||
dataGridViewCellStyle14.Alignment = DataGridViewContentAlignment.MiddleLeft;
|
||||
dataGridViewCellStyle14.BackColor = System.Drawing.Color.FromArgb(243, 249, 255);
|
||||
dataGridViewCellStyle14.Font = new System.Drawing.Font("宋体", 12F);
|
||||
dataGridViewCellStyle14.ForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle14.SelectionBackColor = System.Drawing.Color.FromArgb(80, 160, 255);
|
||||
dataGridViewCellStyle14.SelectionForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle14.WrapMode = DataGridViewTriState.True;
|
||||
dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle14;
|
||||
dataGridViewCellStyle15.BackColor = System.Drawing.Color.White;
|
||||
dataGridViewCellStyle15.ForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridViewCellStyle15.SelectionBackColor = System.Drawing.Color.FromArgb(220, 236, 255);
|
||||
dataGridViewCellStyle15.SelectionForeColor = System.Drawing.Color.FromArgb(48, 48, 48);
|
||||
dataGridView.RowsDefaultCellStyle = dataGridViewCellStyle15;
|
||||
dataGridView.SelectedIndex = -1;
|
||||
dataGridView.Size = new System.Drawing.Size(569, 245);
|
||||
dataGridView.TabIndex = 3;
|
||||
@ -252,10 +256,12 @@ namespace Sunny.UI
|
||||
btnClear.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
btnClear.Name = "btnClear";
|
||||
btnClear.Size = new System.Drawing.Size(80, 29);
|
||||
btnClear.Symbol = 61666;
|
||||
btnClear.Symbol = 361666;
|
||||
btnClear.SymbolOffset = new System.Drawing.Point(0, 1);
|
||||
btnClear.SymbolSize = 22;
|
||||
btnClear.TabIndex = 2;
|
||||
btnClear.Text = "清除";
|
||||
btnClear.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnClear.Click += btnClear_Click;
|
||||
//
|
||||
// btnSearch
|
||||
@ -267,9 +273,11 @@ namespace Sunny.UI
|
||||
btnSearch.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
btnSearch.Name = "btnSearch";
|
||||
btnSearch.Size = new System.Drawing.Size(80, 29);
|
||||
btnSearch.Symbol = 61442;
|
||||
btnSearch.Symbol = 361442;
|
||||
btnSearch.SymbolOffset = new System.Drawing.Point(0, 1);
|
||||
btnSearch.TabIndex = 1;
|
||||
btnSearch.Text = "搜索";
|
||||
btnSearch.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnSearch.Click += btnSearch_Click;
|
||||
//
|
||||
// edtFilter
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
|
@ -78,6 +78,7 @@ namespace Sunny.UI
|
||||
treeView.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
treeView.Name = "treeView";
|
||||
treeView.RadiusSides = UICornerRadiusSides.None;
|
||||
treeView.ScrollBarStyleInherited = false;
|
||||
treeView.ShowText = false;
|
||||
treeView.Size = new System.Drawing.Size(250, 176);
|
||||
treeView.TabIndex = 0;
|
||||
@ -129,6 +130,7 @@ namespace Sunny.UI
|
||||
btnCancel.Size = new System.Drawing.Size(80, 29);
|
||||
btnCancel.StyleCustomMode = true;
|
||||
btnCancel.Symbol = 361453;
|
||||
btnCancel.SymbolOffset = new System.Drawing.Point(0, 1);
|
||||
btnCancel.SymbolSize = 22;
|
||||
btnCancel.TabIndex = 1;
|
||||
btnCancel.Text = "取消";
|
||||
@ -144,6 +146,7 @@ namespace Sunny.UI
|
||||
btnOK.MinimumSize = new System.Drawing.Size(1, 1);
|
||||
btnOK.Name = "btnOK";
|
||||
btnOK.Size = new System.Drawing.Size(80, 29);
|
||||
btnOK.SymbolOffset = new System.Drawing.Point(0, 1);
|
||||
btnOK.SymbolSize = 22;
|
||||
btnOK.TabIndex = 0;
|
||||
btnOK.Text = "确定";
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
|
@ -270,7 +270,7 @@ namespace Sunny.UI
|
||||
tabPage3.Controls.Add(p3);
|
||||
tabPage3.Location = new Point(0, 40);
|
||||
tabPage3.Name = "tabPage3";
|
||||
tabPage3.Size = new Size(461, 277);
|
||||
tabPage3.Size = new Size(200, 60);
|
||||
tabPage3.TabIndex = 2;
|
||||
tabPage3.Text = "tabPage3";
|
||||
tabPage3.UseVisualStyleBackColor = true;
|
||||
@ -285,7 +285,7 @@ namespace Sunny.UI
|
||||
p3.MinimumSize = new Size(1, 1);
|
||||
p3.Name = "p3";
|
||||
p3.RadiusSides = UICornerRadiusSides.None;
|
||||
p3.Size = new Size(461, 277);
|
||||
p3.Size = new Size(200, 60);
|
||||
p3.Style = UIStyle.Custom;
|
||||
p3.TabIndex = 2;
|
||||
p3.Text = null;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
|
@ -1,7 +1,7 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2025 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2025 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
@ -9,13 +9,13 @@
|
||||
*
|
||||
* SunnyUI can be used for free under the GPL-3.0 license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UIAnalogMeter.cs
|
||||
* 文件说明: 仪表
|
||||
* 文件作者: Luca Bonotto
|
||||
* 开源协议: CPOL
|
||||
* 引用地址: https://www.codeproject.com/Articles/24945/Analog-Meter
|
||||
* 文件名称: UIAnalogMeter.cs
|
||||
* 文件说明: 仪表
|
||||
* 文件作者: Luca Bonotto
|
||||
* 开源协议: CPOL
|
||||
* 引用地址: https://www.codeproject.com/Articles/24945/Analog-Meter
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
@ -42,6 +42,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[Description("仪表控件")]
|
||||
public class UIAnalogMeter : UIControl
|
||||
{
|
||||
#region Enumerator
|
||||
@ -320,9 +321,9 @@ namespace Sunny.UI
|
||||
#region Events delegates
|
||||
|
||||
/// <summary>
|
||||
/// 重载控件尺寸变更
|
||||
/// 重载控件尺寸变更
|
||||
/// </summary>
|
||||
/// <param name="e">参数</param>
|
||||
/// <param name="e">参数</param>
|
||||
protected override void OnSizeChanged(EventArgs e)
|
||||
{
|
||||
base.OnSizeChanged(e);
|
||||
@ -333,9 +334,9 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重载绘图
|
||||
/// 重载绘图
|
||||
/// </summary>
|
||||
/// <param name="e">绘图参数</param>
|
||||
/// <param name="e">绘图参数</param>
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (Width <= 0 || Height <= 0) return;
|
||||
|
@ -37,6 +37,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Symbol")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("头像控件")]
|
||||
public sealed class UIAvatar : UIControl, ISymbol, IZoomScale
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -35,6 +35,7 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
[DefaultProperty("Power")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("电池电量控件")]
|
||||
public sealed class UIBattery : UIControl
|
||||
{
|
||||
private Color colorDanger = UIColor.Orange;
|
||||
|
@ -22,6 +22,7 @@
|
||||
* 2022-03-19: V3.1.1 重构主题配色
|
||||
* 2023-05-12: V3.3.6 重构DrawString函数
|
||||
* 2023-09-17: V3.4.2 增加Readonly,禁用鼠标点击,可通过代码设置ItemIndex
|
||||
* 2025-04-03: V3.8.2 增加SetItemColor,设置单个节点颜色,可以用RemoveItemColor移除
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -41,6 +42,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("ItemIndexChanged")]
|
||||
[DefaultProperty("ItemIndex")]
|
||||
[Description("面包屑导航条控件")]
|
||||
public class UIBreadcrumb : UIControl
|
||||
{
|
||||
/// <summary>
|
||||
@ -111,6 +113,20 @@ namespace Sunny.UI
|
||||
|
||||
private readonly ConcurrentDictionary<int, Point[]> ClickArea = new ConcurrentDictionary<int, Point[]>();
|
||||
|
||||
private readonly ConcurrentDictionary<int, Color> ItemsColor = new();
|
||||
|
||||
public void SetItemColor(int index, Color color)
|
||||
{
|
||||
ItemsColor[index] = color;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
public void RemoveItemColor(int index)
|
||||
{
|
||||
ItemsColor.TryRemove(index, out _);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 步骤个数
|
||||
/// </summary>
|
||||
@ -230,7 +246,9 @@ namespace Sunny.UI
|
||||
ClickArea[index] = pts;
|
||||
}
|
||||
|
||||
using Brush br = new SolidBrush(index <= ItemIndex ? SelectedColor : UnSelectedColor);
|
||||
Color color = index <= ItemIndex ? SelectedColor : UnSelectedColor;
|
||||
if (ItemsColor.TryGetValue(index, out var cc)) color = cc;
|
||||
using Brush br = new SolidBrush(color);
|
||||
g.FillPolygon(br, points.ToArray());
|
||||
|
||||
g.DrawString(item.ToString(), Font, index <= ItemIndex ? ForeColor : UnSelectedForeColor,
|
||||
|
@ -52,6 +52,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("按钮控件")]
|
||||
public class UIButton : UIControl, IButtonControl
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -30,6 +30,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("日历控件")]
|
||||
public class UICalendar : UIUserControl, ITranslate
|
||||
{
|
||||
public UICalendar()
|
||||
|
@ -42,6 +42,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("CheckedChanged")]
|
||||
[DefaultProperty("Checked")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("复选框控件")]
|
||||
public class UICheckBox : UIControl
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -44,6 +44,7 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
[DefaultProperty("Items")]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[Description("多选框组控件")]
|
||||
public class UICheckBoxGroup : UIGroupBox
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -41,6 +41,7 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
[DefaultProperty("ValueChanged")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("颜色选择框控件")]
|
||||
public sealed class UIColorPicker : UIDropControl
|
||||
{
|
||||
private void InitializeComponent()
|
||||
|
@ -43,6 +43,7 @@
|
||||
* 2024-10-28: V3.7.2 增加了SelectionChangeCommitted事件,下拉框显示鼠标点击条目时响应
|
||||
* 2024-11-10: V3.7.2 增加StyleDropDown属性,手动修改Style时设置此属性以修改下拉框主题
|
||||
* 2024-11-10: V3.7.2 删除ScrollBarColor、ScrollBarBackColor、ScrollBarStyleInherited属性
|
||||
* 2025-03-18: V3.8.2 修复过滤下拉框跟随主题配色
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -60,6 +61,7 @@ namespace Sunny.UI
|
||||
[DefaultProperty("Items")]
|
||||
[DefaultEvent("SelectedIndexChanged")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("组合框控件")]
|
||||
[LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue")]
|
||||
public sealed partial class UIComboBox : UIDropControl, IToolTip, IHideDropDown
|
||||
{
|
||||
@ -157,7 +159,10 @@ namespace Sunny.UI
|
||||
if (!FilterItemForm.Visible)
|
||||
{
|
||||
filterForm.Style = StyleDropDown;
|
||||
if (StyleDropDown != UIStyle.Inherited) filterForm.Style = StyleDropDown;
|
||||
if (StyleDropDown != UIStyle.Inherited)
|
||||
filterForm.Style = StyleDropDown;
|
||||
else
|
||||
filterForm.Style = UIStyles.Style;
|
||||
FilterItemForm.Show(this, new Size(DropDownWidth < Width ? Width : DropDownWidth, CalcItemFormHeight()));
|
||||
edit.Focus();
|
||||
}
|
||||
@ -735,6 +740,7 @@ namespace Sunny.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
if (StyleDropDown != UIStyle.Inherited) filterForm.Style = StyleDropDown;
|
||||
if (FilterItemForm.Visible)
|
||||
{
|
||||
FilterItemForm.Close();
|
||||
@ -956,7 +962,7 @@ namespace Sunny.UI
|
||||
public Color ItemRectColor
|
||||
{
|
||||
get => ListBox.RectColor;
|
||||
set => ListBox.RectColor = value;
|
||||
set => FilterListBox.RectColor = ListBox.RectColor = value;
|
||||
}
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultProperty("ValueChanged")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("表格列表框控件")]
|
||||
public class UIComboDataGridView : UIDropControl, IToolTip
|
||||
{
|
||||
private void InitializeComponent()
|
||||
|
@ -41,6 +41,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("NodeSelected")]
|
||||
[DefaultProperty("Nodes")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("树形列表框控件")]
|
||||
public class UIComboTreeView : UIDropControl, IToolTip
|
||||
{
|
||||
public UIComboTreeView()
|
||||
|
@ -31,6 +31,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("上下文菜单")]
|
||||
public sealed class UIContextMenuStrip : ContextMenuStrip, IStyleInterface, IZoomScale
|
||||
{
|
||||
private ContextMenuColorTable ColorTable = new ContextMenuColorTable();
|
||||
|
@ -50,6 +50,7 @@
|
||||
* 2024-06-19: V3.6.7 增加AddDateTimeColumn,解决默认时间列不显示秒数的问题
|
||||
* 2024-08-27: V3.7.0 增加属性AutoScrollToBottom,数据更新时是否自动滚动到最后一行
|
||||
* 2024-09-04: V3.7.0 解决有隐藏行时,滚动条滚动时出错的问题
|
||||
* 2025-04-21: V3.8.3 修复数据更新时是否自动滚动到最后一行
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -60,6 +61,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("表格控件")]
|
||||
public class UIDataGridView : DataGridView, IStyleInterface, IZoomScale
|
||||
{
|
||||
private readonly UIScrollBar VBar = new UIScrollBar();
|
||||
@ -1095,7 +1097,7 @@ namespace Sunny.UI
|
||||
//选中最后一行
|
||||
this.Rows[this.RowCount - 1].Selected = true;
|
||||
//滚动到最后一行
|
||||
SetRowHeight(this.RowCount - 1);
|
||||
this.FirstDisplayedScrollingRowIndex = this.RowCount - 1;
|
||||
//如果需要滚动到底部(右侧),使用下面的代码
|
||||
//this.FirstDisplayedCell = this.Rows[this.RowCount - 1].Cells[this.Columns.Count - 1];
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("表格页脚控件")]
|
||||
public sealed class UIDataGridViewFooter : UIControl
|
||||
{
|
||||
public UIDataGridViewFooter()
|
||||
|
@ -40,6 +40,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultProperty("Value")]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[Description("日期选择框控件")]
|
||||
public sealed partial class UIDatePicker : UIDropControl, IToolTip
|
||||
{
|
||||
public delegate void OnDateTimeChanged(object sender, DateTime value);
|
||||
|
@ -38,6 +38,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultProperty("Value")]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[Description("日期时间选择框控件")]
|
||||
public sealed class UIDatetimePicker : UIDropControl, IToolTip
|
||||
{
|
||||
private void InitializeComponent()
|
||||
|
@ -19,6 +19,7 @@
|
||||
* 2023-12-01: V3.6.1 增加文件说明
|
||||
* 2024-01-23: V3.6.3 更新绘制
|
||||
* 2024-10-22: V3.7.2 增加DPI支持
|
||||
* 2025-04-08: V3.8.2 增加ShowText属性,可以显示文字 #IBY64V
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
@ -40,6 +41,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("冷液晶显示LCD标签控件")]
|
||||
public class UIDigitalLabel : UIControl
|
||||
{
|
||||
public UIDigitalLabel()
|
||||
@ -52,6 +54,22 @@ namespace Sunny.UI
|
||||
BackColor = Color.Black;
|
||||
}
|
||||
|
||||
private bool _showText = false;
|
||||
|
||||
[Description("是否显示文字"), Category("SunnyUI"), DefaultValue(false)]
|
||||
public new bool ShowText
|
||||
{
|
||||
get => _showText;
|
||||
set
|
||||
{
|
||||
if (_showText != value)
|
||||
{
|
||||
_showText = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double digitalValue;
|
||||
|
||||
[Description("浮点数"), Category("SunnyUI")]
|
||||
@ -106,7 +124,8 @@ namespace Sunny.UI
|
||||
using Font font = DigitalFont.Instance.GetFont(UIStyles.DPIScale ? DigitalSize / UIDPIScale.SystemDPIScale : DigitalSize);
|
||||
using Brush br = new SolidBrush(ForeColor);
|
||||
|
||||
string text = Value.ToString("F" + DecimalPlaces);
|
||||
string text = ShowText ? Text : Value.ToString("F" + DecimalPlaces);
|
||||
|
||||
SizeF sf = e.Graphics.MeasureString(text, font);
|
||||
float y = (Height - sf.Height) / 2.0f + 1 + Padding.Top;
|
||||
float x = Padding.Left;
|
||||
|
@ -31,7 +31,8 @@
|
||||
* 2023-03-24: V3.3.3 删除ForbidInput属性,使用Inputable属性
|
||||
* 2023-12-28: V3.6.2 修复设置Style时按钮颜色不一致
|
||||
* 2024-08-27: V3.6.9 修改编辑框字体与显示字体一致
|
||||
* 2024-08-27: V3.7.0 增加加按钮字体图标的偏移位置
|
||||
* 2024-08-27: V3.7.0 增加按钮字体图标的偏移位置
|
||||
* 2025-03-16: V3.8.2 增加按钮字体图标的大小属性
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -43,6 +44,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[Description("数字上下选择框控件")]
|
||||
public sealed partial class UIDoubleUpDown : UIPanel, IToolTip
|
||||
{
|
||||
public delegate void OnValueChanged(object sender, double value);
|
||||
@ -157,6 +159,14 @@ namespace Sunny.UI
|
||||
set => step = Math.Abs(value);
|
||||
}
|
||||
|
||||
[DefaultValue(24)]
|
||||
[Description("按钮字体图标大小"), Category("SunnyUI")]
|
||||
public int ButtonSymbolSize
|
||||
{
|
||||
get => btnDec.SymbolSize;
|
||||
set => btnDec.SymbolSize = btnAdd.SymbolSize = value;
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
|
4
SunnyUI/Controls/UIDoubleUpDown.designer.cs
generated
4
SunnyUI/Controls/UIDoubleUpDown.designer.cs
generated
@ -46,7 +46,7 @@
|
||||
btnDec.Padding = new System.Windows.Forms.Padding(26, 4, 0, 0);
|
||||
btnDec.RadiusSides = UICornerRadiusSides.LeftTop | UICornerRadiusSides.LeftBottom;
|
||||
btnDec.Size = new System.Drawing.Size(29, 29);
|
||||
btnDec.Symbol = 61544;
|
||||
btnDec.Symbol = 361544;
|
||||
btnDec.TabIndex = 0;
|
||||
btnDec.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnDec.TipsText = null;
|
||||
@ -65,7 +65,7 @@
|
||||
btnAdd.Padding = new System.Windows.Forms.Padding(26, 3, 0, 0);
|
||||
btnAdd.RadiusSides = UICornerRadiusSides.RightTop | UICornerRadiusSides.RightBottom;
|
||||
btnAdd.Size = new System.Drawing.Size(29, 29);
|
||||
btnAdd.Symbol = 61543;
|
||||
btnAdd.Symbol = 361543;
|
||||
btnAdd.TabIndex = 1;
|
||||
btnAdd.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnAdd.TipsText = null;
|
||||
|
@ -42,6 +42,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("滚动容器控件")]
|
||||
public class UIFlowLayoutPanel : UIPanel, IToolTip
|
||||
{
|
||||
private UIVerScrollBarEx VBar;
|
||||
|
@ -32,6 +32,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("Gif动态头像控件")]
|
||||
public class UIGifAvatar : UIControl, IZoomScale
|
||||
{
|
||||
private Image image;
|
||||
|
@ -34,6 +34,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[DefaultProperty("Text")]
|
||||
[Description("组框控件")]
|
||||
public partial class UIGroupBox : UIPanel
|
||||
{
|
||||
public UIGroupBox()
|
||||
|
@ -43,6 +43,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("顶部图标按钮控件")]
|
||||
public class UIHeaderButton : UIControl, IButtonControl, ISymbol
|
||||
{
|
||||
public UIHeaderButton()
|
||||
|
@ -32,6 +32,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("水平滚动条控件")]
|
||||
public sealed class UIHorScrollBar : UIControl
|
||||
{
|
||||
public UIHorScrollBar()
|
||||
|
@ -30,6 +30,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("水平滚动条控件")]
|
||||
public class UIHorScrollBarEx : UIControl
|
||||
{
|
||||
public UIHorScrollBarEx()
|
||||
|
@ -35,6 +35,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultProperty("Text")]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[Description("IP地址输入框控件")]
|
||||
public sealed partial class UIIPTextBox : UIPanel
|
||||
{
|
||||
private IPAddress _value;
|
||||
|
@ -32,6 +32,7 @@ namespace Sunny.UI
|
||||
/// <summary>
|
||||
/// 图像按钮
|
||||
/// </summary>
|
||||
[Description("图像按钮控件")]
|
||||
public sealed class UIImageButton : PictureBox, IStyleInterface, IZoomScale, IFormTranslator
|
||||
{
|
||||
private bool IsPress;
|
||||
|
@ -38,6 +38,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("ItemClick")]
|
||||
[Description("图片列表框控件")]
|
||||
public sealed partial class UIImageListBox : UIPanel, IToolTip
|
||||
{
|
||||
private readonly ImageListBox listbox = new ImageListBox();
|
||||
|
@ -30,7 +30,8 @@
|
||||
* 2023-03-24: V3.3.3 删除ForbidInput属性,使用Inputable属性
|
||||
* 2023-12-28: V3.6.2 修复设置Style时按钮颜色不一致
|
||||
* 2024-08-27: V3.6.9 修改编辑框字体与显示字体一致
|
||||
* 2024-08-27: V3.7.0 增加加按钮字体图标的偏移位置
|
||||
* 2024-08-27: V3.7.0 增加按钮字体图标的偏移位置
|
||||
* 2025-03-16: V3.8.2 增加按钮字体图标的大小属性
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -42,6 +43,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[Description("数字上下选择框控件")]
|
||||
public sealed partial class UIIntegerUpDown : UIPanel, IToolTip
|
||||
{
|
||||
public delegate void OnValueChanged(object sender, int value);
|
||||
@ -164,6 +166,14 @@ namespace Sunny.UI
|
||||
}
|
||||
}
|
||||
|
||||
[DefaultValue(24)]
|
||||
[Description("按钮字体图标大小"), Category("SunnyUI")]
|
||||
public int ButtonSymbolSize
|
||||
{
|
||||
get => btnDec.SymbolSize;
|
||||
set => btnDec.SymbolSize = btnAdd.SymbolSize = value;
|
||||
}
|
||||
|
||||
[Description("最大值"), Category("SunnyUI")]
|
||||
[DefaultValue(int.MaxValue)]
|
||||
public int Maximum
|
||||
|
4
SunnyUI/Controls/UIIntegerUpDown.designer.cs
generated
4
SunnyUI/Controls/UIIntegerUpDown.designer.cs
generated
@ -46,7 +46,7 @@
|
||||
btnDec.Padding = new System.Windows.Forms.Padding(26, 4, 0, 0);
|
||||
btnDec.RadiusSides = UICornerRadiusSides.LeftTop | UICornerRadiusSides.LeftBottom;
|
||||
btnDec.Size = new System.Drawing.Size(29, 29);
|
||||
btnDec.Symbol = 61544;
|
||||
btnDec.Symbol = 361544;
|
||||
btnDec.TabIndex = 0;
|
||||
btnDec.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnDec.TipsText = null;
|
||||
@ -65,7 +65,7 @@
|
||||
btnAdd.Padding = new System.Windows.Forms.Padding(26, 3, 0, 0);
|
||||
btnAdd.RadiusSides = UICornerRadiusSides.RightTop | UICornerRadiusSides.RightBottom;
|
||||
btnAdd.Size = new System.Drawing.Size(29, 29);
|
||||
btnAdd.Symbol = 61543;
|
||||
btnAdd.Symbol = 361543;
|
||||
btnAdd.TabIndex = 1;
|
||||
btnAdd.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
|
||||
btnAdd.TipsText = null;
|
||||
|
@ -34,6 +34,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("标签控件")]
|
||||
public class UILabel : Label, IStyleInterface, IZoomScale, IFormTranslator
|
||||
{
|
||||
public UILabel()
|
||||
|
@ -34,6 +34,7 @@ namespace Sunny.UI
|
||||
/// provide a sleek looking representation of an LED light that is sizable,
|
||||
/// has a transparent background and can be set to different colors.
|
||||
/// </summary>
|
||||
[Description("LED灯控件")]
|
||||
public class UILedBulb : Control, IZoomScale
|
||||
{
|
||||
#region Public and Private Members
|
||||
|
@ -31,6 +31,7 @@ namespace Sunny.UI
|
||||
/// LED显示屏
|
||||
/// </summary>
|
||||
[DefaultProperty("Text")]
|
||||
[Description("LED显示屏控件")]
|
||||
public class UILedDisplay : Control
|
||||
{
|
||||
#region 组件设计器生成的代码
|
||||
|
@ -18,6 +18,7 @@
|
||||
*
|
||||
* 2021-04-11: V3.0.2 增加文件说明
|
||||
* 2022-03-19: V3.1.1 重构主题配色
|
||||
* 2025-03-31: V3.8.2 重构显示位置,并增加Padding属性关联显示
|
||||
******************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
@ -30,6 +31,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("LED标签控件")]
|
||||
public class UILedLabel : UIControl
|
||||
{
|
||||
public UILedLabel()
|
||||
@ -47,8 +49,7 @@ namespace Sunny.UI
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
int width = CharCount * IntervalOn * 5 +
|
||||
CharCount * IntervalIn * 4 + (CharCount + 1) * IntervalOn + CharCount * IntervalIn;
|
||||
int width = (IntervalOn + IntervalIn) * 6 * CharCount;
|
||||
int height = IntervalOn * 7 + IntervalIn * 6;
|
||||
|
||||
float left = 0;
|
||||
@ -56,22 +57,22 @@ namespace Sunny.UI
|
||||
switch (TextAlign)
|
||||
{
|
||||
case ContentAlignment.TopLeft:
|
||||
left = 0;
|
||||
top = 0;
|
||||
left = IntervalOn + IntervalIn + Padding.Left;
|
||||
top = IntervalOn + IntervalIn + Padding.Top;
|
||||
break;
|
||||
|
||||
case ContentAlignment.TopCenter:
|
||||
left = (Width - width) / 2.0f;
|
||||
top = 0;
|
||||
top = IntervalOn + IntervalIn + Padding.Top;
|
||||
break;
|
||||
|
||||
case ContentAlignment.TopRight:
|
||||
left = Width - width;
|
||||
top = 0;
|
||||
left = Width - width - Padding.Right;
|
||||
top = IntervalOn + IntervalIn + Padding.Top;
|
||||
break;
|
||||
|
||||
case ContentAlignment.MiddleLeft:
|
||||
left = 0;
|
||||
left = IntervalOn + IntervalIn + Padding.Left;
|
||||
top = (Height - height) / 2.0f;
|
||||
break;
|
||||
|
||||
@ -81,23 +82,23 @@ namespace Sunny.UI
|
||||
break;
|
||||
|
||||
case ContentAlignment.MiddleRight:
|
||||
left = Width - width;
|
||||
left = Width - width - Padding.Right;
|
||||
top = (Height - height) / 2.0f;
|
||||
break;
|
||||
|
||||
case ContentAlignment.BottomLeft:
|
||||
left = 0;
|
||||
top = Height - height;
|
||||
left = IntervalOn + IntervalIn + Padding.Left;
|
||||
top = Height - height - (IntervalOn + IntervalIn) - Padding.Bottom;
|
||||
break;
|
||||
|
||||
case ContentAlignment.BottomCenter:
|
||||
left = (Width - width) / 2.0f;
|
||||
top = Height - height;
|
||||
top = Height - height - (IntervalOn + IntervalIn) - Padding.Bottom;
|
||||
break;
|
||||
|
||||
case ContentAlignment.BottomRight:
|
||||
left = Width - width;
|
||||
top = Height - height;
|
||||
left = Width - width - Padding.Right;
|
||||
top = Height - height - (IntervalOn + IntervalIn) - Padding.Bottom;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -105,7 +106,8 @@ namespace Sunny.UI
|
||||
foreach (char c in Text)
|
||||
{
|
||||
float charStart = left + (IntervalOn + IntervalIn) * 6 * idx;
|
||||
byte[] bts = UILedChars.Chars.ContainsKey(c) ? UILedChars.Chars[c] : UILedChars.Chars[' '];
|
||||
byte[] bts = UILedChars.Chars[' '];
|
||||
if (UILedChars.Chars.TryGetValue(c, out var bytes)) bts = bytes;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
byte bt = bts[i];
|
||||
@ -116,12 +118,7 @@ namespace Sunny.UI
|
||||
bool bon = array[7 - j];
|
||||
if (bon)
|
||||
{
|
||||
e.Graphics.FillRectangle(
|
||||
ForeColor,
|
||||
btStart,
|
||||
top + (IntervalOn + IntervalIn) * j,
|
||||
IntervalOn,
|
||||
IntervalOn);
|
||||
e.Graphics.FillRectangle(ForeColor, btStart, top + (IntervalOn + IntervalIn) * j, IntervalOn, IntervalOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
[DefaultEvent("TimerTick")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("LED计时器控件")]
|
||||
public sealed class UILedStopwatch : UILedDisplay
|
||||
{
|
||||
private readonly System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
|
||||
|
@ -40,6 +40,7 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
[ToolboxItem(true)]
|
||||
[Description("提示灯控件")]
|
||||
public sealed class UILight : UIControl
|
||||
{
|
||||
private Timer timer;
|
||||
|
@ -34,6 +34,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("分割线控件")]
|
||||
public sealed class UILine : UIControl
|
||||
{
|
||||
public UILine()
|
||||
|
@ -45,6 +45,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("ItemClick")]
|
||||
[DefaultProperty("Items")]
|
||||
[Description("列表框控件")]
|
||||
public sealed class UIListBox : UIPanel, IToolTip
|
||||
{
|
||||
private readonly ListBoxEx listbox = new ListBoxEx();
|
||||
|
@ -29,6 +29,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("带颜色标签控件")]
|
||||
public sealed class UIMarkLabel : UILabel
|
||||
{
|
||||
public UIMarkLabel()
|
||||
|
@ -28,6 +28,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("下拉菜单按钮控件")]
|
||||
public class UIMenuButton : UISymbolButton
|
||||
{
|
||||
private bool _showDropArrow = true;
|
||||
|
@ -19,15 +19,16 @@
|
||||
* 2021-08-15: V3.0.6 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using Sunny.UI.Win32;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using Sunny.UI.Win32;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("Tick")]
|
||||
[DefaultProperty("Interval")]
|
||||
[Description("毫秒定时器控件")]
|
||||
public class UIMillisecondTimer : Component
|
||||
{
|
||||
public event EventHandler Tick;
|
||||
|
@ -34,6 +34,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("迷你分页控件")]
|
||||
public class UIMiniPagination : UIPanel
|
||||
{
|
||||
public delegate void OnPageChangeEventHandler(object sender, object pagingSource, int pageIndex, int count);
|
||||
|
@ -42,6 +42,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("MenuItemClick")]
|
||||
[DefaultProperty("Nodes")]
|
||||
[Description("导航栏控件")]
|
||||
public sealed partial class UINavBar : ScrollableControl, IStyleInterface, IZoomScale
|
||||
{
|
||||
public readonly TreeView Menu = new TreeView();
|
||||
|
@ -39,6 +39,7 @@
|
||||
* 2023-11-16: V3.5.2 重构主题
|
||||
* 2024-04-13: V3.6.5 修复通过代码设置背景色无效的问题
|
||||
* 2024-05-17: V3.6.6 防止控件闪烁
|
||||
* 2025-04-17: V3.8.3 增加节点文字居中的属性
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -52,6 +53,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("MenuItemClick")]
|
||||
[DefaultProperty("Nodes")]
|
||||
[Description("导航菜单控件")]
|
||||
public sealed class UINavMenu : TreeView, IStyleInterface, IZoomScale
|
||||
{
|
||||
public delegate void OnMenuItemClick(TreeNode node, NavMenuItem item, int pageIndex);
|
||||
@ -105,6 +107,22 @@ namespace Sunny.UI
|
||||
selectedHighColor = UIStyles.Blue.NavMenuMenuSelectedColor;
|
||||
}
|
||||
|
||||
private NodeTextAlign _nodeTextAlign = NodeTextAlign.Left;
|
||||
|
||||
[DefaultValue(NodeTextAlign.Left), Category("SunnyUI"), Description("节点文字显示位置")]
|
||||
public NodeTextAlign NodeTextAlign
|
||||
{
|
||||
get => _nodeTextAlign;
|
||||
set
|
||||
{
|
||||
if (_nodeTextAlign != value)
|
||||
{
|
||||
_nodeTextAlign = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
@ -696,13 +714,25 @@ namespace Sunny.UI
|
||||
e.Graphics.FillRectangle(SelectedColor, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height)));
|
||||
}
|
||||
|
||||
e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleLeft);
|
||||
if (NodeTextAlign == NodeTextAlign.Left)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleLeft);
|
||||
if (NodeTextAlign == NodeTextAlign.TextAreaCenter)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleCenter);
|
||||
if (NodeTextAlign == NodeTextAlign.Center)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, ItemHeight), ContentAlignment.MiddleCenter);
|
||||
|
||||
e.Graphics.FillRectangle(SelectedHighColor, new Rectangle(0, e.Bounds.Y, 4, e.Bounds.Height));
|
||||
}
|
||||
else if (e.Node == CurrentNode && (e.State & TreeNodeStates.Hot) != 0)
|
||||
{
|
||||
e.Graphics.FillRectangle(HoverColor, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height)));
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleLeft);
|
||||
|
||||
if (NodeTextAlign == NodeTextAlign.Left)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleLeft);
|
||||
if (NodeTextAlign == NodeTextAlign.TextAreaCenter)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleCenter);
|
||||
if (NodeTextAlign == NodeTextAlign.Center)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, ItemHeight), ContentAlignment.MiddleCenter);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -713,7 +743,13 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
e.Graphics.FillRectangle(color, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height)));
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleLeft);
|
||||
|
||||
if (NodeTextAlign == NodeTextAlign.Left)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleLeft);
|
||||
if (NodeTextAlign == NodeTextAlign.TextAreaCenter)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(drawLeft, e.Bounds.Y, e.Bounds.Width - drawLeft, ItemHeight), ContentAlignment.MiddleCenter);
|
||||
if (NodeTextAlign == NodeTextAlign.Center)
|
||||
e.Graphics.DrawString(e.Node.Text, Font, ForeColor, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, ItemHeight), ContentAlignment.MiddleCenter);
|
||||
}
|
||||
|
||||
//画右侧图标
|
||||
|
@ -205,6 +205,13 @@ namespace Sunny.UI
|
||||
}
|
||||
}
|
||||
|
||||
public enum NodeTextAlign
|
||||
{
|
||||
Left,
|
||||
Center,
|
||||
TextAreaCenter
|
||||
}
|
||||
|
||||
public class NavMenuItem : ISymbol
|
||||
{
|
||||
public string Text { get; set; }
|
||||
|
@ -34,6 +34,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[Description("模拟数字键盘输入框控件")]
|
||||
public class UINumPadTextBox : UIDropControl, IToolTip, IHideDropDown
|
||||
{
|
||||
public UINumPadTextBox()
|
||||
|
@ -36,6 +36,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("分页控件")]
|
||||
public class UIPagination : UIPanel, ITranslate
|
||||
{
|
||||
public delegate void OnPageChangeEventHandler(object sender, object pagingSource, int pageIndex, int count);
|
||||
|
@ -36,6 +36,7 @@ using System.Drawing.Drawing2D;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("面板控件")]
|
||||
public partial class UIPanel : UIUserControl
|
||||
{
|
||||
public UIPanel()
|
||||
|
@ -30,6 +30,7 @@ using System.Drawing.Drawing2D;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("管道控件")]
|
||||
public class UIPipe : UIControl
|
||||
{
|
||||
public UIPipe()
|
||||
|
@ -38,6 +38,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[Description("进度条控件")]
|
||||
public sealed class UIProcessBar : UIControl
|
||||
{
|
||||
private int maximum = 100;
|
||||
|
@ -31,6 +31,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("进度指示器控件")]
|
||||
public sealed class UIProgressIndicator : UIControl
|
||||
{
|
||||
private readonly Timer timer;
|
||||
|
@ -41,6 +41,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("CheckedChanged")]
|
||||
[DefaultProperty("Checked")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("单选框控件")]
|
||||
public sealed class UIRadioButton : UIControl
|
||||
{
|
||||
public delegate void OnValueChanged(object sender, bool value);
|
||||
|
@ -40,6 +40,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultProperty("Items")]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[Description("单选框组控件")]
|
||||
public class UIRadioButtonGroup : UIGroupBox
|
||||
{
|
||||
public delegate void OnValueChanged(object sender, int index, string text);
|
||||
|
@ -38,6 +38,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("TextChanged")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("富文本输入框控件")]
|
||||
public sealed class UIRichTextBox : UIPanel, IToolTip
|
||||
{
|
||||
private UIScrollBar bar;
|
||||
|
@ -19,7 +19,6 @@
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using Sunny.UI.Properties;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
@ -31,6 +30,7 @@ namespace Sunny.UI
|
||||
/// </summary>
|
||||
[ToolboxItem(true)]
|
||||
[DefaultProperty("Angle")]
|
||||
[Description("圆形图表控件")]
|
||||
public sealed class UIRoundMeter : UIControl
|
||||
{
|
||||
/// <summary>
|
||||
@ -44,7 +44,7 @@ namespace Sunny.UI
|
||||
Custom,
|
||||
|
||||
/// <summary>
|
||||
/// The GPS
|
||||
/// The Gps
|
||||
/// </summary>
|
||||
Gps,
|
||||
|
||||
@ -132,14 +132,14 @@ namespace Sunny.UI
|
||||
|
||||
if (value == TMeterType.Gps)
|
||||
{
|
||||
BackgroundImage = Resources.gps1;
|
||||
AngleImage = Resources.gps_postion;
|
||||
BackgroundImage = Sunny.UI.Properties.Resources.gps1;
|
||||
AngleImage = Sunny.UI.Properties.Resources.gps_postion;
|
||||
}
|
||||
|
||||
if (value == TMeterType.Wind)
|
||||
{
|
||||
BackgroundImage = Resources.wind;
|
||||
AngleImage = Resources.wind_postion;
|
||||
BackgroundImage = Sunny.UI.Properties.Resources.wind;
|
||||
AngleImage = Sunny.UI.Properties.Resources.wind_postion;
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
|
@ -37,6 +37,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[Description("圆形进度条控件")]
|
||||
public class UIRoundProcess : UIControl
|
||||
{
|
||||
public UIRoundProcess()
|
||||
|
@ -27,6 +27,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("刻度尺控件")]
|
||||
public class UIRuler : UIControl
|
||||
{
|
||||
private UITrackBar.BarDirection direction = UITrackBar.BarDirection.Horizontal;
|
||||
|
@ -33,6 +33,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Value")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("滚动条控件")]
|
||||
public sealed class UIScrollBar : UIControl
|
||||
{
|
||||
public UIScrollBar()
|
||||
|
@ -33,6 +33,7 @@ using System.Windows.Forms;
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
[Description("滚动文字控件")]
|
||||
public class UIScrollingText : UIControl
|
||||
{
|
||||
private readonly Timer timer;
|
||||
|
@ -31,6 +31,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Level")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("信号强度显示控件")]
|
||||
public class UISignal : UIControl
|
||||
{
|
||||
public UISignal()
|
||||
|
@ -33,6 +33,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("平滑文字带边框的标签控件")]
|
||||
public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale, IFormTranslator
|
||||
{
|
||||
private PointF point;
|
||||
|
@ -30,6 +30,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("分割容器控件")]
|
||||
public sealed class UISplitContainer : SplitContainer, IStyleInterface, IZoomScale
|
||||
{
|
||||
private enum UIMouseType
|
||||
|
@ -25,6 +25,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
{
|
||||
[Description("根据状态显示图片控件")]
|
||||
public class UIStatusBox : PictureBox
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -37,6 +37,7 @@ namespace Sunny.UI
|
||||
[DefaultEvent("ValueChanged")]
|
||||
[DefaultProperty("Active")]
|
||||
[ToolboxItem(true)]
|
||||
[Description("开关控件")]
|
||||
public sealed class UISwitch : UIControl
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -36,6 +36,7 @@ namespace Sunny.UI
|
||||
{
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("字体图标按钮控件")]
|
||||
public class UISymbolButton : UIButton, ISymbol
|
||||
{
|
||||
private int _symbolSize = 24;
|
||||
|
@ -36,6 +36,7 @@ namespace Sunny.UI
|
||||
[ToolboxItem(true)]
|
||||
[DefaultEvent("Click")]
|
||||
[DefaultProperty("Text")]
|
||||
[Description("带字体图标的标签控件")]
|
||||
public sealed class UISymbolLabel : UIControl, ISymbol
|
||||
{
|
||||
private int _symbolSize = 24;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user