* UIButton:增加ShowFocusLine,可获得焦点并显示

This commit is contained in:
Sunny 2020-06-23 23:21:53 +08:00
parent fcc37179e7
commit d508e93218
8 changed files with 66 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -160,6 +160,7 @@
this.uiButton1.Name = "uiButton1";
this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(219)))), ((int)(((byte)(227)))));
this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(197)))), ((int)(((byte)(222)))), ((int)(((byte)(255)))));
this.uiButton1.ShowFocusLine = true;
this.uiButton1.Size = new System.Drawing.Size(100, 35);
this.uiButton1.Style = Sunny.UI.UIStyle.White;
this.uiButton1.StyleCustomMode = true;
@ -172,6 +173,7 @@
this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiButton2.Location = new System.Drawing.Point(144, 50);
this.uiButton2.Name = "uiButton2";
this.uiButton2.ShowFocusLine = true;
this.uiButton2.Size = new System.Drawing.Size(100, 35);
this.uiButton2.StyleCustomMode = true;
this.uiButton2.TabIndex = 1;
@ -189,6 +191,7 @@
this.uiButton3.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(190)))), ((int)(((byte)(40)))));
this.uiButton3.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(136)))), ((int)(((byte)(202)))), ((int)(((byte)(81)))));
this.uiButton3.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(168)))), ((int)(((byte)(35)))));
this.uiButton3.ShowFocusLine = true;
this.uiButton3.Size = new System.Drawing.Size(100, 35);
this.uiButton3.Style = Sunny.UI.UIStyle.Green;
this.uiButton3.StyleCustomMode = true;
@ -207,6 +210,7 @@
this.uiButton4.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
this.uiButton4.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(127)))), ((int)(((byte)(128)))));
this.uiButton4.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(202)))), ((int)(((byte)(87)))), ((int)(((byte)(89)))));
this.uiButton4.ShowFocusLine = true;
this.uiButton4.Size = new System.Drawing.Size(100, 35);
this.uiButton4.Style = Sunny.UI.UIStyle.Red;
this.uiButton4.StyleCustomMode = true;
@ -225,6 +229,7 @@
this.uiButton5.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(155)))), ((int)(((byte)(40)))));
this.uiButton5.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(174)))), ((int)(((byte)(86)))));
this.uiButton5.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(137)))), ((int)(((byte)(43)))));
this.uiButton5.ShowFocusLine = true;
this.uiButton5.Size = new System.Drawing.Size(100, 35);
this.uiButton5.Style = Sunny.UI.UIStyle.Orange;
this.uiButton5.StyleCustomMode = true;
@ -243,6 +248,7 @@
this.uiButton6.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
this.uiButton6.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
this.uiButton6.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
this.uiButton6.ShowFocusLine = true;
this.uiButton6.Size = new System.Drawing.Size(100, 35);
this.uiButton6.Style = Sunny.UI.UIStyle.Gray;
this.uiButton6.StyleCustomMode = true;

View File

@ -23,6 +23,7 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
// ReSharper disable All
@ -33,7 +34,7 @@ namespace Sunny.UI
[DefaultEvent("Click")]
[DefaultProperty("Text")]
[ToolboxItem(true)]
public class UIButton : UIControl
public class UIButton : UIControl, IButtonControl
{
public UIButton()
{
@ -65,6 +66,12 @@ namespace Sunny.UI
}
}
protected override void OnClick(EventArgs e)
{
Focus();
base.OnClick(e);
}
private bool showTips = false;
[Description("是否显示角标"), Category("自定义")]
@ -136,6 +143,19 @@ namespace Sunny.UI
e.Graphics.FillEllipse(UIColor.Red, x, y, sfMax, sfMax);
e.Graphics.DrawString(TipsText, TipsFont, Color.White, x + sfMax / 2.0f - sf.Width / 2.0f, y + sfMax / 2.0f - sf.Height / 2.0f);
}
if (Focused && ShowFocusLine)
{
Rectangle rect = new Rectangle(2, 2, Width - 5, Height - 5);
var path = rect.CreateRoundedRectanglePath(Radius);
using (Pen pn = new Pen(ForeColor))
{
pn.DashStyle = DashStyle.Dot;
e.Graphics.DrawPath(pn, path);
}
path.Dispose();
}
}
private bool selected;
@ -304,5 +324,25 @@ namespace Sunny.UI
IsHover = true;
Invalidate();
}
public void NotifyDefault(bool value)
{
}
[DefaultValue(DialogResult.None)]
public DialogResult DialogResult { get; set; } = DialogResult.None;
protected override void OnKeyDown(KeyEventArgs e)
{
if (Focused && e.KeyCode == Keys.Space)
{
PerformClick();
}
base.OnKeyDown(e);
}
[DefaultValue(false)]
public bool ShowFocusLine { get; set; }
}
}

View File

@ -694,5 +694,21 @@ namespace Sunny.UI
Invalidate();
}
}
/// <summary>引发 <see cref="E:System.Windows.Forms.Control.GotFocus" /> 事件。</summary>
/// <param name="e">包含事件数据的 <see cref="T:System.EventArgs" />。</param>
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
this.Invalidate();
}
/// <summary>引发 <see cref="M:System.Windows.Forms.ButtonBase.OnLostFocus(System.EventArgs)" /> 事件。</summary>
/// <param name="e">包含事件数据的 <see cref="T:System.EventArgs" />。</param>
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
this.Invalidate();
}
}
}

View File

@ -1,5 +1,8 @@
+ 增加; - 删除; * 修改
2020.06.23
* UIButton增加ShowFocusLine可获得焦点并显示
2020.06.22
* UIForm增加WindowStateChange事件判断WindowState状态调整ShowFullScreen全屏显示