* UITabControl:重绘左右按钮

This commit is contained in:
Sunny 2020-06-27 16:53:32 +08:00
parent 8372ca96f0
commit af63124c44
12 changed files with 764 additions and 1250 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -925,6 +925,7 @@
// uiImageButton1
//
this.uiImageButton1.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiImageButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiImageButton1.Image = global::Sunny.UI.Demo.Properties.Resources.dashboard0;
this.uiImageButton1.ImageHover = global::Sunny.UI.Demo.Properties.Resources.dashboard;
this.uiImageButton1.ImagePress = global::Sunny.UI.Demo.Properties.Resources.dashboard0;
@ -939,6 +940,7 @@
// uiImageButton2
//
this.uiImageButton2.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiImageButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiImageButton2.Image = global::Sunny.UI.Demo.Properties.Resources.relationship0;
this.uiImageButton2.ImageHover = global::Sunny.UI.Demo.Properties.Resources.relationship;
this.uiImageButton2.ImagePress = global::Sunny.UI.Demo.Properties.Resources.relationship0;
@ -952,6 +954,7 @@
// uiImageButton3
//
this.uiImageButton3.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiImageButton3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiImageButton3.Image = global::Sunny.UI.Demo.Properties.Resources.save0;
this.uiImageButton3.ImageHover = global::Sunny.UI.Demo.Properties.Resources.save;
this.uiImageButton3.ImagePress = global::Sunny.UI.Demo.Properties.Resources.save0;
@ -965,6 +968,8 @@
// uiImageButton4
//
this.uiImageButton4.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiImageButton4.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiImageButton4.ForeColor = System.Drawing.Color.Red;
this.uiImageButton4.Image = global::Sunny.UI.Demo.Properties.Resources.dashboard0;
this.uiImageButton4.ImageHover = global::Sunny.UI.Demo.Properties.Resources.dashboard;
this.uiImageButton4.ImageOffset = new System.Drawing.Point(12, 5);

View File

@ -33,7 +33,7 @@
//
// lblTitle
//
this.lblTitle.Text = "FLogin";
this.lblTitle.Text = "SunnyUI.Net Login Form";
//
// FLogin
//
@ -41,9 +41,9 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(750, 450);
this.LoginImage = Sunny.UI.UILoginForm.UILoginImage.Login5;
this.LoginImage = Sunny.UI.UILoginForm.UILoginImage.Login6;
this.Name = "FLogin";
this.Text = "FLogin";
this.Text = "SunnyUI.Net Login Form";
this.ButtonLoginClick += new System.EventHandler(this.FLogin_ButtonLoginClick);
this.ResumeLayout(false);
this.PerformLayout();

File diff suppressed because it is too large Load Diff

View File

@ -31,11 +31,6 @@ namespace Sunny.UI
/// </summary>
public sealed class UIImageButton : PictureBox
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private IContainer components;
private bool IsPress;
private bool IsHover;
@ -46,7 +41,6 @@ namespace Sunny.UI
private bool selected;
private string text;
private ContentAlignment textAlign = ContentAlignment.MiddleCenter;
private Font font = UIFontColor.Font;
private Color foreColor = UIFontColor.Primary;
[Category("外观")]
@ -83,10 +77,10 @@ namespace Sunny.UI
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override Font Font
{
get => font;
get => base.Font;
set
{
font = value;
base.Font = value;
Invalidate();
}
}
@ -119,7 +113,6 @@ namespace Sunny.UI
/// </summary>
public UIImageButton()
{
InitializeComponent();
SetDefaultControlStyles();
SuspendLayout();
BorderStyle = BorderStyle.None;
@ -128,6 +121,7 @@ namespace Sunny.UI
Height = 35;
Version = UIGlobal.Version;
Cursor = Cursors.Hand;
base.Font = UIFontColor.Font;
}
public string Version { get; }
@ -208,20 +202,6 @@ namespace Sunny.UI
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing)
{
components?.Dispose();
}
base.Dispose(disposing);
}
private void SetDefaultControlStyles()
{
SetStyle(ControlStyles.UserPaint, true);
@ -395,18 +375,5 @@ namespace Sunny.UI
break;
}
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new Container();
}
#endregion
}
}

View File

@ -149,6 +149,20 @@ namespace Sunny.UI
tabControl = ctrl;
}
public NavMenuItem this[int index]
{
get
{
if (index < 0 || index >= tabControl.TabPages.Count)
{
throw new ArgumentOutOfRangeException();
}
TabPage page = tabControl.TabPages[index];
return PageItems.ContainsKey(page) ? PageItems[page] : null;
}
}
public UIPage AddPage(int pageIndex, UIPage page)
{
page.PageIndex = pageIndex;
@ -313,6 +327,8 @@ namespace Sunny.UI
public Guid PageGuid { get; set; } = Guid.Empty;
public bool AlwaysOpen { get; set; } = false;
public NavMenuItem()
{
}
@ -322,6 +338,7 @@ namespace Sunny.UI
Text = page.Text;
PageIndex = page.PageIndex;
PageGuid = page.PageGuid;
AlwaysOpen = page.AlwaysOpen;
}
public NavMenuItem(string text, int pageIndex)

View File

@ -17,6 +17,7 @@
* : 2020-01-01
*
* 2020-01-01: V2.2.0
* 2020-06-27: V2.2.5
******************************************************************************/
using System;
@ -66,40 +67,19 @@ namespace Sunny.UI
[DefaultValue(true)]
public bool ForbidCtrlTab { get; set; } = true;
public void SelectPage(int pageIndex)
{
Helper.SelectPage(pageIndex);
}
public void SelectPage(int pageIndex) => Helper.SelectPage(pageIndex);
public void SelectPage(Guid pageGuid)
{
Helper.SelectPage(pageGuid);
}
public void SelectPage(Guid pageGuid) => Helper.SelectPage(pageGuid);
public void AddPage(UIPage page)
{
Helper.AddPage(page);
}
public void AddPage(UIPage page) => Helper.AddPage(page);
public void AddPage(int pageIndex, UITabControl page)
{
Helper.AddPage(pageIndex, page);
}
public void AddPage(int pageIndex, UITabControl page) => Helper.AddPage(pageIndex, page);
public void AddPage(int pageIndex, UITabControlMenu page)
{
Helper.AddPage(pageIndex, page);
}
public void AddPage(int pageIndex, UITabControlMenu page) => Helper.AddPage(pageIndex, page);
public void AddPage(Guid guid, UITabControl page)
{
Helper.AddPage(guid, page);
}
public void AddPage(Guid guid, UITabControl page) => Helper.AddPage(guid, page);
public void AddPage(Guid guid, UITabControlMenu page)
{
Helper.AddPage(guid, page);
}
public void AddPage(Guid guid, UITabControlMenu page) => Helper.AddPage(guid, page);
public string Version { get; }
@ -401,9 +381,16 @@ namespace Sunny.UI
}
g.DrawString(TabPages[index].Text, Font, index == SelectedIndex ? tabSelectedForeColor : TabUnSelectedForeColor, textLeft, TabRect.Top + 2 + (TabRect.Height - sf.Height) / 2.0f);
var menuItem = Helper[index];
bool showButton = menuItem == null || !menuItem.AlwaysOpen;
if (showButton)
{
if (ShowCloseButton || (ShowActiveCloseButton && index == SelectedIndex))
{
g.DrawFontImage(61453, 20, index == SelectedIndex ? tabSelectedForeColor : TabUnSelectedForeColor, new Rectangle(TabRect.Width - 28, TabRect.Top, 24, TabRect.Height));
g.DrawFontImage(77, 28, index == SelectedIndex ? tabSelectedForeColor : TabUnSelectedForeColor, new Rectangle(TabRect.Width - 28, TabRect.Top, 24, TabRect.Height));
}
}
// 绘制图标
@ -543,13 +530,7 @@ namespace Sunny.UI
{
Graphics g = e.Graphics;
Rectangle rect = e.ClipRectangle;
Color upButtonBaseColor = tabBackColor;
Color upButtonBorderColor = tabBackColor;
Color upButtonArrowColor = tabUnSelectedForeColor;
Color downButtonBaseColor = tabBackColor;
Color downButtonBorderColor = tabBackColor;
Color downButtonArrowColor = tabUnSelectedForeColor;
Rectangle upButtonRect = rect;
@ -573,125 +554,47 @@ namespace Sunny.UI
{
//鼠标按下
if (e.MouseInUpButton)
{
upButtonArrowColor = GetColor(tabBackColor, 0, -35, -24, -9);
}
upButtonArrowColor = Color.FromArgb(200, TabSelectedHighColor);
else
{
downButtonArrowColor = GetColor(tabBackColor, 0, -35, -24, -9);
}
downButtonArrowColor = Color.FromArgb(200, TabSelectedHighColor);
}
else
{
//鼠标移动
if (e.MouseInUpButton)
{
upButtonArrowColor = GetColor(tabBackColor, 0, 35, 24, 9);
}
upButtonArrowColor = TabSelectedHighColor;
else
{
downButtonArrowColor = GetColor(tabBackColor, 0, 35, 24, 9);
}
downButtonArrowColor = TabSelectedHighColor;
}
}
}
else
{
upButtonBaseColor = SystemColors.Control;
upButtonBorderColor = SystemColors.ControlDark;
upButtonArrowColor = SystemColors.ControlDark;
downButtonBaseColor = SystemColors.Control;
downButtonBorderColor = SystemColors.ControlDark;
downButtonArrowColor = SystemColors.ControlDark;
}
g.SmoothingMode = SmoothingMode.AntiAlias;
//Color color = Enabled ? BackColor : SystemColors.Control;
//rect.Inflate(1, 1);
//g.FillRectangle(color, rect);
RenderButton(g, upButtonRect, upButtonBaseColor, upButtonBorderColor, upButtonArrowColor, ArrowDirection.Left);
RenderButton(g, downButtonRect, downButtonBaseColor, downButtonBorderColor, downButtonArrowColor, ArrowDirection.Right);
RenderButton(g, upButtonRect, upButtonArrowColor, ArrowDirection.Left);
RenderButton(g, downButtonRect, downButtonArrowColor, ArrowDirection.Right);
UpDownButtonPaintEventHandler handler = Events[EventPaintUpDownButton] as UpDownButtonPaintEventHandler;
handler?.Invoke(this, e);
}
internal void RenderButton(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color arrowColor, ArrowDirection direction)
internal void RenderButton(Graphics g, Rectangle rect, Color arrowColor, ArrowDirection direction)
{
//RenderBackgroundInternal(g, rect, baseColor, borderColor, 0.45f, true, LinearGradientMode.Vertical);
switch (direction)
{
case ArrowDirection.Left:
g.DrawFontImage(61700, (int)(30 * this.ItemSize.Height / 40), arrowColor, rect);
g.DrawFontImage(61700, 24, arrowColor, rect);
break;
case ArrowDirection.Right:
g.DrawFontImage(61701, (int)(30 * this.ItemSize.Height / 40), arrowColor, rect, 1);
g.DrawFontImage(61701, 24, arrowColor, rect, 1);
break;
}
}
private Color GetColor(Color colorBase, int a, int r, int g, int b)
{
int a0 = colorBase.A;
int r0 = colorBase.R;
int g0 = colorBase.G;
int b0 = colorBase.B;
if (a + a0 > 255) { a = 255; } else { a = Math.Max(a + a0, 0); }
if (r + r0 > 255) { r = 255; } else { r = Math.Max(r + r0, 0); }
if (g + g0 > 255) { g = 255; } else { g = Math.Max(g + g0, 0); }
if (b + b0 > 255) { b = 255; } else { b = Math.Max(b + b0, 0); }
return Color.FromArgb(a, r, g, b);
}
internal void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, float basePosition, bool drawBorder, LinearGradientMode mode)
{
using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
{
Color[] colors = new Color[4];
colors[0] = GetColor(baseColor, 0, 35, 24, 9);
colors[1] = GetColor(baseColor, 0, 13, 8, 3);
colors[2] = baseColor;
colors[3] = GetColor(baseColor, 0, 68, 69, 54);
ColorBlend blend = new ColorBlend();
blend.Positions = new[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
blend.Colors = colors;
brush.InterpolationColors = blend;
g.FillRectangle(brush, rect);
}
if (baseColor.A > 80)
{
Rectangle rectTop = rect;
if (mode == LinearGradientMode.Vertical)
{
rectTop.Height = (int)(rectTop.Height * basePosition);
}
else
{
rectTop.Width = (int)(rect.Width * basePosition);
}
using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
{
g.FillRectangle(brushAlpha, rectTop);
}
}
if (drawBorder)
{
using (Pen pen = new Pen(borderColor))
{
g.DrawRectangle(pen, rect);
}
}
}
private static readonly object EventPaintUpDownButton = new object();
private const string UpDownButtonClassName = "msctls_updown32";
private UpDownButtonNativeWindow _upDownButtonNativeWindow;
@ -765,13 +668,12 @@ namespace Sunny.UI
{
private UITabControl _owner;
private bool _bPainting;
private Rectangle clipRect = new Rectangle();
private Rectangle clipRect;
public UpDownButtonNativeWindow(UITabControl owner)
{
_owner = owner;
AssignHandle(owner.UpDownButtonHandle);
}
private bool LeftKeyPressed()
@ -811,8 +713,8 @@ namespace Sunny.UI
case NativeMethods.WM_PAINT:
if (!_bPainting)
{
Point UpDownButtonLocation = new Point((int)(_owner.Size.Width - _owner.ItemSize.Height * 1.5), 0);
Size UpDownButtonSize = new Size((int)(_owner.ItemSize.Height * 1.5), _owner.ItemSize.Height);
Point UpDownButtonLocation = new Point(_owner.Size.Width - 52, 0);
Size UpDownButtonSize = new Size(52, _owner.ItemSize.Height);
clipRect = new Rectangle(UpDownButtonLocation, UpDownButtonSize);
NativeMethods.MoveWindow(Handle, UpDownButtonLocation.X, UpDownButtonLocation.Y, clipRect.Width, clipRect.Height);
@ -829,6 +731,7 @@ namespace Sunny.UI
base.WndProc(ref m);
}
break;
default:
base.WndProc(ref m);
break;
@ -852,10 +755,6 @@ namespace Sunny.UI
public const int VK_LBUTTON = 0x1;
public const int VK_RBUTTON = 0x2;
private const int TCM_FIRST = 0x1300;
public const int TCM_GETITEMRECT = (TCM_FIRST + 10);
public static readonly IntPtr TRUE = new IntPtr(1);
[StructLayout(LayoutKind.Sequential)]
@ -910,16 +809,10 @@ namespace Sunny.UI
[DllImport("user32.dll")]
public static extern short GetKeyState(int nVirtKey);
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, ref RECT lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(ref Point lpPoint);
[DllImport("user32.dll")]
public extern static int OffsetRect(ref RECT lpRect, int x, int y);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PtInRect([In] ref RECT lprc, Point pt);
@ -928,26 +821,15 @@ namespace Sunny.UI
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetClientRect(IntPtr hWnd, ref RECT r);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint = true);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool IsWindowVisible(IntPtr hwnd);
}
public delegate void UpDownButtonPaintEventHandler(object sender, UpDownButtonPaintEventArgs e);
public class UpDownButtonPaintEventArgs : PaintEventArgs
{
private bool _mouseOver;
private bool _mousePress;
private bool _mouseInUpButton;
public UpDownButtonPaintEventArgs(
Graphics graphics,
Rectangle clipRect,
@ -956,25 +838,16 @@ namespace Sunny.UI
bool mouseInUpButton)
: base(graphics, clipRect)
{
_mouseOver = mouseOver;
_mousePress = mousePress;
_mouseInUpButton = mouseInUpButton;
MouseOver = mouseOver;
MousePress = mousePress;
MouseInUpButton = mouseInUpButton;
}
public bool MouseOver
{
get { return _mouseOver; }
}
public bool MouseOver { get; }
public bool MousePress
{
get { return _mousePress; }
}
public bool MousePress { get; }
public bool MouseInUpButton
{
get { return _mouseInUpButton; }
}
public bool MouseInUpButton { get; }
}
}
}

View File

@ -97,6 +97,9 @@ namespace Sunny.UI
}
}
[DefaultValue(false),Description("在Frame框架中不被关闭")]
public bool AlwaysOpen { get; set; }
protected virtual void SymbolChange()
{

View File

@ -1,8 +1,12 @@
+ 增加; - 删除; * 修改
2020.06.27
* UITabControl重绘左右按钮
2020.06.26
+ UIDoughnutChart增加控件环状图
+ UILoginForm新增两张背景图
* 对PNG图片进行了压缩减少了SunnyUI.Dll的大小
2020.06.25
+ UIScrollingText增加控件滚动文字