diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 8a3c3dcc..cce62a5c 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/Bin/net45/SunnyUI.dll b/Bin/net45/SunnyUI.dll index 568b782d..0c235def 100644 Binary files a/Bin/net45/SunnyUI.dll and b/Bin/net45/SunnyUI.dll differ diff --git a/Bin/net5.0-windows/SunnyUI.dll b/Bin/net5.0-windows/SunnyUI.dll index 5b7916eb..667e0d3e 100644 Binary files a/Bin/net5.0-windows/SunnyUI.dll and b/Bin/net5.0-windows/SunnyUI.dll differ diff --git a/Bin/net5.0-windows/ref/SunnyUI.dll b/Bin/net5.0-windows/ref/SunnyUI.dll index ad4d7c46..801f5223 100644 Binary files a/Bin/net5.0-windows/ref/SunnyUI.dll and b/Bin/net5.0-windows/ref/SunnyUI.dll differ diff --git a/Bin/netcoreapp3.1/SunnyUI.dll b/Bin/netcoreapp3.1/SunnyUI.dll index 28c8395c..2c8ea617 100644 Binary files a/Bin/netcoreapp3.1/SunnyUI.dll and b/Bin/netcoreapp3.1/SunnyUI.dll differ diff --git a/SunnyUI/Pages/UIPage.Designer.cs b/SunnyUI/Pages/UIPage.Designer.cs index aab19adf..961bf6a2 100644 --- a/SunnyUI/Pages/UIPage.Designer.cs +++ b/SunnyUI/Pages/UIPage.Designer.cs @@ -45,7 +45,6 @@ this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "UIPage"; - this.Shown += new System.EventHandler(this.UIPage_Shown); this.ResumeLayout(false); } diff --git a/SunnyUI/Pages/UIPage.cs b/SunnyUI/Pages/UIPage.cs index ff85f8ca..18cc3736 100644 --- a/SunnyUI/Pages/UIPage.cs +++ b/SunnyUI/Pages/UIPage.cs @@ -25,7 +25,6 @@ using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Design; -using System.Reflection; using System.Windows.Forms; namespace Sunny.UI @@ -214,6 +213,18 @@ namespace Sunny.UI } } } + + if (AllowShowTitle && !AllowAddControlOnTitle && e.Control.Top < TitleHeight) + { + e.Control.Top = Padding.Top; + } + } + + [DefaultValue(false)] + [Description("允许在标题栏放置控件"), Category("SunnyUI")] + public bool AllowAddControlOnTitle + { + get; set; } public virtual void Init() @@ -233,20 +244,20 @@ namespace Sunny.UI //EventLoad(); } - private void EventLoad() - { - Type type = this.GetType().BaseType; - while (type.Name != "Form") - { - type = type.BaseType; - } - - FieldInfo targetMethod = type.GetField("EVENT_LOAD", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); - object obj = (object)targetMethod.GetValue(this); - - EventHandler handler = (EventHandler)this.Events[obj]; - handler?.Invoke(this, EventArgs.Empty); - } + // private void EventLoad() + // { + // Type type = this.GetType().BaseType; + // while (type.Name != "Form") + // { + // type = type.BaseType; + // } + // + // FieldInfo targetMethod = type.GetField("EVENT_LOAD", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); + // object obj = (object)targetMethod.GetValue(this); + // + // EventHandler handler = (EventHandler)this.Events[obj]; + // handler?.Invoke(this, EventArgs.Empty); + // } public virtual void Final() { @@ -291,6 +302,11 @@ namespace Sunny.UI if (Width <= 0 || Height <= 0) return; + if (AllowShowTitle) + { + e.Graphics.FillRectangle(TitleFillColor, 0, 0, Width, TitleHeight); + } + if (RectSides != ToolStripStatusLabelBorderSides.None) { if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Left)) @@ -302,6 +318,100 @@ namespace Sunny.UI if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Bottom)) e.Graphics.DrawLine(RectColor, 0, Height - 1, Width - 1, Height - 1); } + + if (!AllowShowTitle) return; + if (Symbol > 0) + { + e.Graphics.DrawFontImage(Symbol, SymbolSize, TitleForeColor, new Rectangle(ImageInterval, 0, SymbolSize, TitleHeight)); + } + + SizeF sf = e.Graphics.MeasureString(Text, Font); + e.Graphics.DrawString(Text, Font, TitleForeColor, + Symbol > 0 ? ImageInterval * 2 + SymbolSize : ImageInterval, (TitleHeight - sf.Height) / 2); + + e.Graphics.SetHighQuality(); + if (ControlBox) + { + if (InControlBox) + { + e.Graphics.FillRectangle(UIColor.Red, ControlBoxRect); + } + + e.Graphics.DrawLine(Color.White, + ControlBoxRect.Left + ControlBoxRect.Width / 2 - 5, + ControlBoxRect.Top + ControlBoxRect.Height / 2 - 5, + ControlBoxRect.Left + ControlBoxRect.Width / 2 + 5, + ControlBoxRect.Top + ControlBoxRect.Height / 2 + 5); + e.Graphics.DrawLine(Color.White, + ControlBoxRect.Left + ControlBoxRect.Width / 2 - 5, + ControlBoxRect.Top + ControlBoxRect.Height / 2 + 5, + ControlBoxRect.Left + ControlBoxRect.Width / 2 + 5, + ControlBoxRect.Top + ControlBoxRect.Height / 2 - 5); + } + } + + protected override void OnMouseClick(MouseEventArgs e) + { + if (FormBorderStyle == FormBorderStyle.None && ShowTitle) + { + if (InControlBox) + { + InControlBox = false; + Close(); + AfterClose(); + } + } + } + + private void AfterClose() + { + Console.WriteLine("Close"); + } + + private Color titleFillColor = Color.FromArgb(76, 76, 76); + + /// + /// 填充颜色,当值为背景色或透明色或空值则不填充 + /// + [Description("标题颜色"), Category("SunnyUI")] + [DefaultValue(typeof(Color), "76, 76, 76")] + public Color TitleFillColor + { + get => titleFillColor; + set + { + titleFillColor = value; + Invalidate(); + } + } + + private Color titleForeColor = Color.White; + + /// + /// 字体颜色 + /// + [Description("字体颜色"), Category("SunnyUI")] + [DefaultValue(typeof(Color), "White")] + public Color TitleForeColor + { + get => titleForeColor; + set + { + titleForeColor = value; + Invalidate(); + } + } + + private int imageInterval = 6; + + public int ImageInterval + { + get => imageInterval; + set + { + imageInterval = Math.Max(2, value); + Invalidate(); + } } protected override void OnBackColorChanged(EventArgs e) @@ -318,11 +428,124 @@ namespace Sunny.UI _style = UIStyle.Custom; } - private void UIPage_Shown(object sender, EventArgs e) + private int titleHeight = 35; + + [Description("面板高度"), Category("SunnyUI")] + [DefaultValue(35)] + public int TitleHeight { - //SetStyle(UIStyles.Style); + get => titleHeight; + set + { + titleHeight = Math.Max(value, 31); + Padding = new Padding(Padding.Left, titleHeight, Padding.Right, Padding.Bottom); + CalcSystemBoxPos(); + Invalidate(); + } } + protected override void OnSizeChanged(EventArgs e) + { + base.OnSizeChanged(e); + CalcSystemBoxPos(); + } + + private bool InControlBox; + + protected override void OnMouseMove(MouseEventArgs e) + { + if (ShowTitle && ControlBox) + { + bool inControlBox = e.Location.InRect(ControlBoxRect); + + if (inControlBox != InControlBox) + { + InControlBox = inControlBox; + Invalidate(); + } + + } + } + + protected override void OnPaddingChanged(EventArgs e) + { + base.OnPaddingChanged(e); + + if (AllowShowTitle) + { + Padding = new Padding(Padding.Left, titleHeight, Padding.Right, Padding.Bottom); + } + } + + [Description("允许显示标题栏"), Category("SunnyUI"), DefaultValue(false)] + public bool AllowShowTitle + { + get => ShowTitle; + set => ShowTitle = value; + } + + /// + /// 是否显示窗体的标题栏 + /// + private bool showTitle; + + /// + /// 是否显示窗体的标题栏 + /// + [Description("是否显示窗体的标题栏"), Category("WindowStyle"), DefaultValue(false)] + public bool ShowTitle + { + get => showTitle; + set + { + showTitle = value; + Padding = new Padding(Padding.Left, value ? titleHeight : 0, Padding.Right, Padding.Bottom); + Invalidate(); + } + } + + + protected override void OnTextChanged(EventArgs e) + { + base.OnTextChanged(e); + Invalidate(); + } + + private void CalcSystemBoxPos() + { + ControlBoxRect = new Rectangle(Width - 6 - 28, titleHeight / 2 - 14, 28, 28); + + } + + private Rectangle ControlBoxRect; + + + /// + /// 是否显示窗体的控制按钮 + /// + private bool controlBox = false; + + /// + /// 是否显示窗体的控制按钮 + /// + [Description("是否显示窗体的控制按钮"), Category("WindowStyle"), DefaultValue(false)] + public new bool ControlBox + { + get => controlBox; + set + { + controlBox = value; + CalcSystemBoxPos(); + Invalidate(); + } + } + + [Browsable(false)] + public new bool MinimizeBox { get; set; } + + [Browsable(false)] + public new bool MaximizeBox { get; set; } + #region 一些辅助窗口 /// diff --git a/SunnyUI/Pages/UITitlePage.Designer.cs b/SunnyUI/Pages/UITitlePage.Designer.cs index 7c8e5ef4..049af86e 100644 --- a/SunnyUI/Pages/UITitlePage.Designer.cs +++ b/SunnyUI/Pages/UITitlePage.Designer.cs @@ -42,7 +42,7 @@ this.PageTitle.Padding = new System.Windows.Forms.Padding(6, 0, 0, 0); this.PageTitle.RadiusSides = Sunny.UI.UICornerRadiusSides.None; this.PageTitle.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; - this.PageTitle.Size = new System.Drawing.Size(1475, 35); + this.PageTitle.Size = new System.Drawing.Size(913, 35); this.PageTitle.Symbol = 0; this.PageTitle.SymbolSize = 24; this.PageTitle.TabIndex = 0; @@ -59,7 +59,7 @@ this.PagePanel.Name = "PagePanel"; this.PagePanel.RadiusSides = Sunny.UI.UICornerRadiusSides.None; this.PagePanel.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; - this.PagePanel.Size = new System.Drawing.Size(1475, 852); + this.PagePanel.Size = new System.Drawing.Size(913, 367); this.PagePanel.TabIndex = 1; this.PagePanel.Text = null; this.PagePanel.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter; @@ -67,7 +67,7 @@ // UITitlePage // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.ClientSize = new System.Drawing.Size(1475, 887); + this.ClientSize = new System.Drawing.Size(913, 402); this.Controls.Add(this.PagePanel); this.Controls.Add(this.PageTitle); this.Name = "UITitlePage"; diff --git a/SunnyUI/Pages/UITitlePage.cs b/SunnyUI/Pages/UITitlePage.cs index 0c033ec9..dc5d5eae 100644 --- a/SunnyUI/Pages/UITitlePage.cs +++ b/SunnyUI/Pages/UITitlePage.cs @@ -52,7 +52,7 @@ namespace Sunny.UI [Description("显示标题"), Category("SunnyUI")] [DefaultValue(true)] - public bool ShowTitle + public new bool ShowTitle { get => showTitle; set => showTitle = value; @@ -73,7 +73,7 @@ namespace Sunny.UI /// [Description("标题颜色"), Category("SunnyUI")] [DefaultValue(typeof(Color), "76, 76, 76")] - public Color TitleFillColor + public new Color TitleFillColor { get => PageTitle.FillColor; set @@ -88,7 +88,7 @@ namespace Sunny.UI /// [Description("字体颜色"), Category("SunnyUI")] [DefaultValue(typeof(Color), "White")] - public Color TitleForeColor + public new Color TitleForeColor { get => PageTitle.ForeColor; set @@ -139,7 +139,7 @@ namespace Sunny.UI ForeColor = uiColor.PageTitleForeColor; } - private int symbol = 0; + private int symbol; public int Symbol { get => symbol;