Compare commits

...

4 Commits

4 changed files with 71 additions and 28 deletions

View File

@ -50,6 +50,7 @@
* 2024-06-19: V3.6.7 AddDateTimeColumn * 2024-06-19: V3.6.7 AddDateTimeColumn
* 2024-08-27: V3.7.0 AutoScrollToBottom * 2024-08-27: V3.7.0 AutoScrollToBottom
* 2024-09-04: V3.7.0 * 2024-09-04: V3.7.0
* 2025-04-21: V3.8.3
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -1096,7 +1097,7 @@ namespace Sunny.UI
//选中最后一行 //选中最后一行
this.Rows[this.RowCount - 1].Selected = true; 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]; //this.FirstDisplayedCell = this.Rows[this.RowCount - 1].Cells[this.Columns.Count - 1];
} }

View File

@ -39,6 +39,7 @@
* 2023-11-16: V3.5.2 * 2023-11-16: V3.5.2
* 2024-04-13: V3.6.5 * 2024-04-13: V3.6.5
* 2024-05-17: V3.6.6 * 2024-05-17: V3.6.6
* 2025-04-17: V3.8.3
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -106,6 +107,22 @@ namespace Sunny.UI
selectedHighColor = UIStyles.Blue.NavMenuMenuSelectedColor; 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) protected override void OnHandleCreated(EventArgs e)
{ {
base.OnHandleCreated(e); base.OnHandleCreated(e);
@ -697,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.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)); e.Graphics.FillRectangle(SelectedHighColor, new Rectangle(0, e.Bounds.Y, 4, e.Bounds.Height));
} }
else if (e.Node == CurrentNode && (e.State & TreeNodeStates.Hot) != 0) 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.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 else
{ {
@ -714,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.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);
} }
//画右侧图标 //画右侧图标

View File

@ -205,6 +205,13 @@ namespace Sunny.UI
} }
} }
public enum NodeTextAlign
{
Left,
Center,
TextAreaCenter
}
public class NavMenuItem : ISymbol public class NavMenuItem : ISymbol
{ {
public string Text { get; set; } public string Text { get; set; }

View File

@ -38,6 +38,8 @@
* 2024-12-12: V3.8.0 #IB7U69 * 2024-12-12: V3.8.0 #IB7U69
* 2025-02-07: V3.8.1 TabPage #IBKDR7 * 2025-02-07: V3.8.1 TabPage #IBKDR7
* 2025-02-13: V3.8.1 线 ShowTabDivider#IBLERL * 2025-02-13: V3.8.1 线 ShowTabDivider#IBLERL
* 2025-04-17: V3.8.3 #IC1XIU
* 2025-04-21: V3.8.3
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -377,9 +379,9 @@ namespace Sunny.UI
} }
/// <summary> /// <summary>
/// 边框颜色 /// 标签页默认背景颜色
/// </summary> /// </summary>
[Description("边框颜色"), Category("SunnyUI")] [Description("标签页默认背景颜色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "56, 56, 56")] [DefaultValue(typeof(Color), "56, 56, 56")]
public Color TabBackColor public Color TabBackColor
{ {
@ -398,7 +400,7 @@ namespace Sunny.UI
private Color tabSelectedColor = Color.FromArgb(36, 36, 36); private Color tabSelectedColor = Color.FromArgb(36, 36, 36);
/// <summary> /// <summary>
/// 边框颜 /// 选中Tab页背景
/// </summary> /// </summary>
[Description("选中Tab页背景色"), Category("SunnyUI")] [Description("选中Tab页背景色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "36, 36, 36")] [DefaultValue(typeof(Color), "36, 36, 36")]
@ -419,9 +421,9 @@ namespace Sunny.UI
private Color tabUnSelectedColor = Color.FromArgb(56, 56, 56); private Color tabUnSelectedColor = Color.FromArgb(56, 56, 56);
/// <summary> /// <summary>
/// 边框颜 /// 未选中Tab页背景
/// </summary> /// </summary>
[Description("选中Tab页背景色"), Category("SunnyUI")] [Description("选中Tab页背景色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "56, 56, 56")] [DefaultValue(typeof(Color), "56, 56, 56")]
public Color TabUnSelectedColor public Color TabUnSelectedColor
{ {
@ -440,7 +442,7 @@ namespace Sunny.UI
private Color tabSelectedForeColor = UIColor.Blue; private Color tabSelectedForeColor = UIColor.Blue;
/// <summary> /// <summary>
/// 边框颜 /// 选中Tab页字体
/// </summary> /// </summary>
[Description("选中Tab页字体色"), Category("SunnyUI")] [Description("选中Tab页字体色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")] [DefaultValue(typeof(Color), "80, 160, 255")]
@ -460,7 +462,7 @@ namespace Sunny.UI
private Color tabUnSelectedForeColor = Color.FromArgb(240, 240, 240); private Color tabUnSelectedForeColor = Color.FromArgb(240, 240, 240);
/// <summary> /// <summary>
/// 边框颜 /// 未选中Tab页字体
/// </summary> /// </summary>
[Description("未选中Tab页字体色"), Category("SunnyUI")] [Description("未选中Tab页字体色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "240, 240, 240")] [DefaultValue(typeof(Color), "240, 240, 240")]
@ -481,7 +483,7 @@ namespace Sunny.UI
private Color tabSelectedHighColor = UIColor.Blue; private Color tabSelectedHighColor = UIColor.Blue;
/// <summary> /// <summary>
/// 边框颜色 /// 选中Tab页高亮
/// </summary> /// </summary>
[Description("选中Tab页高亮"), Category("SunnyUI")] [Description("选中Tab页高亮"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")] [DefaultValue(typeof(Color), "80, 160, 255")]
@ -819,7 +821,6 @@ namespace Sunny.UI
protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e)
{ {
base.OnMouseDown(e); base.OnMouseDown(e);
int removeIndex = -1; int removeIndex = -1;
for (int index = 0; index <= TabCount - 1; index++) for (int index = 0; index <= TabCount - 1; index++)
{ {
@ -838,29 +839,28 @@ namespace Sunny.UI
} }
TabPage tabPage = TabPages[removeIndex]; TabPage tabPage = TabPages[removeIndex];
if (tabPage.Text == MainPage) return;
UIPage uiPage = Helper.GetPage(tabPage); UIPage uiPage = Helper.GetPage(tabPage);
bool show1 = tabPage.Text != MainPage; if (uiPage == null) return;
bool show2 = uiPage == null || !uiPage.AlwaysOpen; if (uiPage.Text == MainPage) return;
bool showButton = show1 && show2; if (uiPage.AlwaysOpen) return;
if (showButton)
if (ShowCloseButton)
{ {
if (ShowCloseButton) if (BeforeRemoveTabPage == null || BeforeRemoveTabPage.Invoke(this, removeIndex))
{
RemoveTabPage(removeIndex);
}
}
else if (ShowActiveCloseButton && removeIndex == SelectedIndex)
{
if (DrawedIndex == removeIndex)
{ {
if (BeforeRemoveTabPage == null || BeforeRemoveTabPage.Invoke(this, removeIndex)) if (BeforeRemoveTabPage == null || BeforeRemoveTabPage.Invoke(this, removeIndex))
{ {
RemoveTabPage(removeIndex); RemoveTabPage(removeIndex);
} }
} }
else if (ShowActiveCloseButton && removeIndex == SelectedIndex)
{
if (DrawedIndex == removeIndex)
{
if (BeforeRemoveTabPage == null || BeforeRemoveTabPage.Invoke(this, removeIndex))
{
RemoveTabPage(removeIndex);
}
}
}
} }
} }