+ UIHorScrollBarEx,UIVerScrollBarEx:重写了两个滚动条
* UIDataGridView:重写了水平滚动条
This commit is contained in:
parent
77ec669592
commit
e705339388
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
BIN
Bin/SunnyUI.pdb
BIN
Bin/SunnyUI.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
16
SunnyUI.Demo/Controls/FScrollBar.Designer.cs
generated
16
SunnyUI.Demo/Controls/FScrollBar.Designer.cs
generated
@ -40,11 +40,13 @@
|
|||||||
this.uiHorScrollBar3 = new Sunny.UI.UIHorScrollBar();
|
this.uiHorScrollBar3 = new Sunny.UI.UIHorScrollBar();
|
||||||
this.uiHorScrollBar4 = new Sunny.UI.UIHorScrollBar();
|
this.uiHorScrollBar4 = new Sunny.UI.UIHorScrollBar();
|
||||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||||
|
this.uiVerScrollBarEx1 = new Sunny.UI.UIVerScrollBarEx();
|
||||||
this.PagePanel.SuspendLayout();
|
this.PagePanel.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// PagePanel
|
// PagePanel
|
||||||
//
|
//
|
||||||
|
this.PagePanel.Controls.Add(this.uiVerScrollBarEx1);
|
||||||
this.PagePanel.Controls.Add(this.uiHorScrollBar4);
|
this.PagePanel.Controls.Add(this.uiHorScrollBar4);
|
||||||
this.PagePanel.Controls.Add(this.uiHorScrollBar3);
|
this.PagePanel.Controls.Add(this.uiHorScrollBar3);
|
||||||
this.PagePanel.Controls.Add(this.uiHorScrollBar2);
|
this.PagePanel.Controls.Add(this.uiHorScrollBar2);
|
||||||
@ -190,6 +192,19 @@
|
|||||||
//
|
//
|
||||||
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
||||||
//
|
//
|
||||||
|
// uiVerScrollBarEx1
|
||||||
|
//
|
||||||
|
this.uiVerScrollBarEx1.BoundsHeight = 10;
|
||||||
|
this.uiVerScrollBarEx1.Font = new System.Drawing.Font("微软雅黑", 12F);
|
||||||
|
this.uiVerScrollBarEx1.LargeChange = 10;
|
||||||
|
this.uiVerScrollBarEx1.Location = new System.Drawing.Point(219, 61);
|
||||||
|
this.uiVerScrollBarEx1.Maximum = 100;
|
||||||
|
this.uiVerScrollBarEx1.Name = "uiVerScrollBarEx1";
|
||||||
|
this.uiVerScrollBarEx1.Size = new System.Drawing.Size(18, 147);
|
||||||
|
this.uiVerScrollBarEx1.TabIndex = 62;
|
||||||
|
this.uiVerScrollBarEx1.Text = "uiVerScrollBarEx1";
|
||||||
|
this.uiVerScrollBarEx1.Value = 0;
|
||||||
|
//
|
||||||
// FScrollBar
|
// FScrollBar
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
|
||||||
@ -216,5 +231,6 @@
|
|||||||
private UIHorScrollBar uiHorScrollBar3;
|
private UIHorScrollBar uiHorScrollBar3;
|
||||||
private UIHorScrollBar uiHorScrollBar2;
|
private UIHorScrollBar uiHorScrollBar2;
|
||||||
private System.Windows.Forms.Timer timer1;
|
private System.Windows.Forms.Timer timer1;
|
||||||
|
private UIVerScrollBarEx uiVerScrollBarEx1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,7 +32,7 @@ namespace Sunny.UI
|
|||||||
public class UIDataGridView : DataGridView, IStyleInterface
|
public class UIDataGridView : DataGridView, IStyleInterface
|
||||||
{
|
{
|
||||||
private readonly UIScrollBar VBar = new UIScrollBar();
|
private readonly UIScrollBar VBar = new UIScrollBar();
|
||||||
private readonly UIHorScrollBar HBar = new UIHorScrollBar();
|
private readonly UIHorScrollBarEx HBar = new UIHorScrollBarEx();
|
||||||
|
|
||||||
public UIDataGridView()
|
public UIDataGridView()
|
||||||
{
|
{
|
||||||
@ -43,14 +43,13 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
VBar.Parent = this;
|
VBar.Parent = this;
|
||||||
VBar.Visible = false;
|
VBar.Visible = false;
|
||||||
VBar.FillColor = UIColor.LightBlue;
|
HBar.FillColor = VBar.FillColor = UIColor.LightBlue;
|
||||||
VBar.ForeColor = UIColor.Blue;
|
VBar.ForeColor = UIColor.Blue;
|
||||||
VBar.StyleCustomMode = true;
|
VBar.StyleCustomMode = true;
|
||||||
VBar.ValueChanged += VBarValueChanged;
|
VBar.ValueChanged += VBarValueChanged;
|
||||||
|
|
||||||
HBar.Parent = this;
|
HBar.Parent = this;
|
||||||
HBar.Visible = false;
|
HBar.Visible = false;
|
||||||
HBar.FillColor = UIColor.LightBlue;
|
|
||||||
HBar.ForeColor = UIColor.Blue;
|
HBar.ForeColor = UIColor.Blue;
|
||||||
HBar.StyleCustomMode = true;
|
HBar.StyleCustomMode = true;
|
||||||
HBar.ValueChanged += HBar_ValueChanged;
|
HBar.ValueChanged += HBar_ValueChanged;
|
||||||
@ -80,41 +79,7 @@ namespace Sunny.UI
|
|||||||
StripeOddColor = UIColor.LightBlue;
|
StripeOddColor = UIColor.LightBlue;
|
||||||
|
|
||||||
VerticalScrollBar.ValueChanged += VerticalScrollBar_ValueChanged;
|
VerticalScrollBar.ValueChanged += VerticalScrollBar_ValueChanged;
|
||||||
HorizontalScrollBar.VisibleChanged += HorizontalScrollBar_VisibleChanged;
|
HorizontalScrollBar.ValueChanged += HorizontalScrollBar_ValueChanged;
|
||||||
}
|
|
||||||
|
|
||||||
private void VerticalScrollBar_ValueChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
VBar.Value = FirstDisplayedScrollingRowIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VBarValueChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
FirstDisplayedScrollingRowIndex = VBar.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HorizontalScrollBar_VisibleChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
HBar.Value = FirstDisplayedScrollingColumnIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HBar_ValueChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
FirstDisplayedScrollingColumnIndex = HBar.Value;
|
|
||||||
// int idx = 0;
|
|
||||||
// for (int i = 0; i < ColumnCount; i++)
|
|
||||||
// {
|
|
||||||
// if (Columns[i].Visible && idx == HBar.Value)
|
|
||||||
// {
|
|
||||||
// FirstDisplayedScrollingColumnIndex = i;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (Columns[i].Visible)
|
|
||||||
// {
|
|
||||||
// idx++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
@ -151,19 +116,26 @@ namespace Sunny.UI
|
|||||||
SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e)
|
private void VerticalScrollBar_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPaint(e);
|
VBar.Value = FirstDisplayedScrollingRowIndex;
|
||||||
|
|
||||||
if (ShowRect)
|
|
||||||
{
|
|
||||||
Color color = RectColor;
|
|
||||||
color = Enabled ? color : UIDisableColor.Fill;
|
|
||||||
e.Graphics.DrawRectangle(color, new Rectangle(0, 0, Width - 1, Height - 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void VBarValueChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FirstDisplayedScrollingRowIndex = VBar.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HorizontalScrollBar_ValueChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
HBar.Value = HorizontalScrollBar.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HBar_ValueChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
HorizontalScrollBar.Value = HBar.Value;
|
||||||
|
HorizontalScrollingOffset = HBar.Value;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetScrollInfo()
|
public void SetScrollInfo()
|
||||||
{
|
{
|
||||||
@ -183,16 +155,12 @@ namespace Sunny.UI
|
|||||||
VBar.Visible = false;
|
VBar.Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (HorizontalScrollBar.Visible)
|
if (HorizontalScrollBar.Visible)
|
||||||
// {
|
|
||||||
// HBar.Maximum = VisibleColumnCount();
|
|
||||||
// HBar.Value = FirstDisplayedScrollingColumnIndex;
|
|
||||||
// HBar.Visible = true;
|
|
||||||
// }
|
|
||||||
if (ColumnCount > DisplayedColumnCount(false))
|
|
||||||
{
|
{
|
||||||
HBar.Maximum = ColumnCount - DisplayedColumnCount(false);
|
HBar.Maximum = HorizontalScrollBar.Maximum;
|
||||||
HBar.Value = FirstDisplayedScrollingColumnIndex;
|
HBar.Value = HorizontalScrollBar.Value;
|
||||||
|
HBar.BoundsWidth = HorizontalScrollBar.Bounds.Width;
|
||||||
|
HBar.LargeChange = HorizontalScrollBar.Maximum / VisibleColumnCount();
|
||||||
HBar.Visible = true;
|
HBar.Visible = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -214,6 +182,18 @@ namespace Sunny.UI
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnPaint(e);
|
||||||
|
|
||||||
|
if (ShowRect)
|
||||||
|
{
|
||||||
|
Color color = RectColor;
|
||||||
|
color = Enabled ? color : UIDisableColor.Fill;
|
||||||
|
e.Graphics.DrawRectangle(color, new Rectangle(0, 0, Width - 1, Height - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnMouseWheel(MouseEventArgs e)
|
protected override void OnMouseWheel(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseWheel(e);
|
base.OnMouseWheel(e);
|
||||||
@ -550,10 +530,10 @@ namespace Sunny.UI
|
|||||||
ClearColumns();
|
ClearColumns();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddRow(params object[] values)
|
// public void AddRow(params object[] values)
|
||||||
{
|
// {
|
||||||
Rows.Add(values);
|
// Rows.Add(values);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class UIDataGridViewHelper
|
public static class UIDataGridViewHelper
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* If you use this code, please keep this note.
|
* If you use this code, please keep this note.
|
||||||
* 如果您使用此代码,请保留此说明。
|
* 如果您使用此代码,请保留此说明。
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* 文件名称: UIScrollBar.cs
|
* 文件名称: UIHorScrollBar.cs
|
||||||
* 文件说明: 水平滚动条
|
* 文件说明: 水平滚动条
|
||||||
* 当前版本: V2.2
|
* 当前版本: V2.2
|
||||||
* 创建日期: 2020-01-01
|
* 创建日期: 2020-01-01
|
||||||
|
277
SunnyUI/Controls/UIHorScrollBarEx.cs
Normal file
277
SunnyUI/Controls/UIHorScrollBarEx.cs
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||||
|
* CopyRight (C) 2012-2020 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.
|
||||||
|
* 如果您使用此代码,请保留此说明。
|
||||||
|
******************************************************************************
|
||||||
|
* 文件名称: UIHorScrollBarEx.cs
|
||||||
|
* 文件说明: 水平滚动条
|
||||||
|
* 当前版本: V2.2
|
||||||
|
* 创建日期: 2020-08-29
|
||||||
|
*
|
||||||
|
* 2020-08-29: V2.2.7 新增水平滚动条
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Sunny.UI
|
||||||
|
{
|
||||||
|
[ToolboxItem(true)]
|
||||||
|
public class UIHorScrollBarEx : UIControl
|
||||||
|
{
|
||||||
|
public UIHorScrollBarEx()
|
||||||
|
{
|
||||||
|
ShowText = false;
|
||||||
|
ShowRect = false;
|
||||||
|
Height = ScrollBarInfo.HorizontalScrollBarHeight() + 1;
|
||||||
|
|
||||||
|
fillColor = UIColor.LightBlue;
|
||||||
|
foreColor = UIColor.Blue;
|
||||||
|
fillHoverColor = Color.FromArgb(111, 168, 255);
|
||||||
|
fillPressColor = Color.FromArgb(74, 131, 229);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int maximum = 100;
|
||||||
|
public int Maximum
|
||||||
|
{
|
||||||
|
get => maximum;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
maximum = value.CheckLowerLimit(2);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LargeChange { get; set; } = 10;
|
||||||
|
|
||||||
|
public int thisValue;
|
||||||
|
public event EventHandler ValueChanged;
|
||||||
|
|
||||||
|
public int Value
|
||||||
|
{
|
||||||
|
get => thisValue;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
thisValue = value.CheckLowerLimit(0);
|
||||||
|
thisValue = value.CheckUpperLimit(Maximum - BoundsWidth);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int boundsWidth = 10;
|
||||||
|
public int BoundsWidth
|
||||||
|
{
|
||||||
|
get => boundsWidth;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
boundsWidth = value.CheckLowerLimit(1);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LeftButtonPos => 16;
|
||||||
|
|
||||||
|
public int RightButtonPos => Width - 16;
|
||||||
|
|
||||||
|
protected override void OnPaintFill(Graphics g, GraphicsPath path)
|
||||||
|
{
|
||||||
|
base.OnPaintFill(g, path);
|
||||||
|
g.Clear(fillColor);
|
||||||
|
|
||||||
|
DrawUpDownArrow(g, true);
|
||||||
|
DrawUpDownArrow(g, false);
|
||||||
|
|
||||||
|
DrawValueBar(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawValueBar(Graphics g)
|
||||||
|
{
|
||||||
|
Color clr = foreColor;
|
||||||
|
if (inCenterArea && IsPress)
|
||||||
|
{
|
||||||
|
clr = fillPressColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int left = 16 + Value * (Width - 32) / Maximum;
|
||||||
|
int width = BoundsWidth * (Width - 32) / Maximum;
|
||||||
|
|
||||||
|
g.SetHighQuality();
|
||||||
|
g.FillRoundRectangle(clr, new Rectangle(left, Height / 2 - 3, width, 6), 5);
|
||||||
|
g.SetDefaultQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rectangle GetUpRect()
|
||||||
|
{
|
||||||
|
var rect = new Rectangle(1, 1, 16, Height - 2);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rectangle GetDownRect()
|
||||||
|
{
|
||||||
|
return new Rectangle(Width - 17, 1, 16, Height - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseDown(e);
|
||||||
|
IsPress = true;
|
||||||
|
|
||||||
|
if (inLeftArea)
|
||||||
|
{
|
||||||
|
int value = (Value - LargeChange).CheckRange(0, Maximum - BoundsWidth);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inRightArea)
|
||||||
|
{
|
||||||
|
int value = (Value + LargeChange).CheckRange(0, Maximum - BoundsWidth);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inCenterArea)
|
||||||
|
{
|
||||||
|
int x = BoundsWidth * (Width - 32) / Maximum;
|
||||||
|
int value = (e.Location.X - x / 2) * maximum / (Width - 32);
|
||||||
|
value = value.CheckRange(0, Maximum - BoundsWidth);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseUp(e);
|
||||||
|
IsPress = false;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseLeave(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseLeave(e);
|
||||||
|
IsPress = false;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseEnter(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseEnter(e);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawUpDownArrow(Graphics g, bool isUp)
|
||||||
|
{
|
||||||
|
Color clr_arrow = foreColor;
|
||||||
|
if ((inLeftArea || inRightArea) && IsPress)
|
||||||
|
{
|
||||||
|
clr_arrow = fillPressColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
g.FillRectangle(fillColor, isUp ? GetUpRect() : GetDownRect());
|
||||||
|
g.SetHighQuality();
|
||||||
|
using (var pen = new Pen(clr_arrow, 2))
|
||||||
|
{
|
||||||
|
Point pt1, pt2, pt3;
|
||||||
|
if (!isUp)
|
||||||
|
{
|
||||||
|
pt1 = new Point(Width - 16 / 2 - 4, Height / 2 - 4);
|
||||||
|
pt2 = new Point(Width - 16 / 2, Height / 2);
|
||||||
|
pt3 = new Point(Width - 16 / 2 - 4, Height / 2 + 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pt1 = new Point(16 / 2 + 4 - 1, Height / 2 - 4);
|
||||||
|
pt2 = new Point(16 / 2 - 1, Height / 2);
|
||||||
|
pt3 = new Point(16 / 2 + 4 - 1, Height / 2 + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
|
||||||
|
}
|
||||||
|
|
||||||
|
g.SetDefaultQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool inLeftArea, inRightArea, inCenterArea;
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseMove(e);
|
||||||
|
inLeftArea = e.Location.X < LeftButtonPos;
|
||||||
|
inRightArea = e.Location.X > RightButtonPos;
|
||||||
|
inCenterArea = e.Location.X >= LeftButtonPos && e.Location.X <= RightButtonPos;
|
||||||
|
|
||||||
|
if (inCenterArea && IsPress)
|
||||||
|
{
|
||||||
|
int x = BoundsWidth * (Width - 32) / Maximum;
|
||||||
|
int value = (e.Location.X - x / 2) * maximum / (Width - 32);
|
||||||
|
value = value.CheckRange(0, Maximum - BoundsWidth);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetStyleColor(UIBaseStyle uiColor)
|
||||||
|
{
|
||||||
|
base.SetStyleColor(uiColor);
|
||||||
|
if (uiColor.IsCustom()) return;
|
||||||
|
|
||||||
|
fillColor = uiColor.PlainColor;
|
||||||
|
foreColor = uiColor.ScrollBarForeColor;
|
||||||
|
fillHoverColor = uiColor.ButtonFillHoverColor;
|
||||||
|
fillPressColor = uiColor.ButtonFillPressColor;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 字体颜色
|
||||||
|
/// </summary>
|
||||||
|
[Description("字体颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
||||||
|
public override Color ForeColor
|
||||||
|
{
|
||||||
|
get => foreColor;
|
||||||
|
set => SetForeColor(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
||||||
|
/// </summary>
|
||||||
|
[Description("填充颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "235, 243, 255")]
|
||||||
|
public Color FillColor
|
||||||
|
{
|
||||||
|
get => fillColor;
|
||||||
|
set => SetFillColor(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Description("鼠标移上颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "111, 168, 255")]
|
||||||
|
public Color HoverColor
|
||||||
|
{
|
||||||
|
get => fillHoverColor;
|
||||||
|
set => SetFillHoveColor(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Description("鼠标按下颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "74, 131, 229")]
|
||||||
|
public Color PressColor
|
||||||
|
{
|
||||||
|
get => fillPressColor;
|
||||||
|
set => SetFillPressColor(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
276
SunnyUI/Controls/UIVerScrollBarEx.cs
Normal file
276
SunnyUI/Controls/UIVerScrollBarEx.cs
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||||
|
* CopyRight (C) 2012-2020 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.
|
||||||
|
* 如果您使用此代码,请保留此说明。
|
||||||
|
******************************************************************************
|
||||||
|
* 文件名称: UIVerScrollBarEx.cs
|
||||||
|
* 文件说明: 垂直滚动条
|
||||||
|
* 当前版本: V2.2
|
||||||
|
* 创建日期: 2020-08-29
|
||||||
|
*
|
||||||
|
* 2020-08-29: V2.2.7 新增水平滚动条
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Sunny.UI
|
||||||
|
{
|
||||||
|
[ToolboxItem(true)]
|
||||||
|
public class UIVerScrollBarEx : UIControl
|
||||||
|
{
|
||||||
|
public UIVerScrollBarEx()
|
||||||
|
{
|
||||||
|
ShowText = false;
|
||||||
|
ShowRect = false;
|
||||||
|
Width = ScrollBarInfo.VerticalScrollBarWidth() + 1;
|
||||||
|
|
||||||
|
fillColor = UIColor.LightBlue;
|
||||||
|
foreColor = UIColor.Blue;
|
||||||
|
fillHoverColor = Color.FromArgb(111, 168, 255);
|
||||||
|
fillPressColor = Color.FromArgb(74, 131, 229);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int maximum = 100;
|
||||||
|
public int Maximum
|
||||||
|
{
|
||||||
|
get => maximum;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
maximum = value.CheckLowerLimit(2);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LargeChange { get; set; } = 10;
|
||||||
|
|
||||||
|
public int thisValue;
|
||||||
|
public event EventHandler ValueChanged;
|
||||||
|
|
||||||
|
public int Value
|
||||||
|
{
|
||||||
|
get => thisValue;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
thisValue = value.CheckLowerLimit(0);
|
||||||
|
thisValue = value.CheckUpperLimit(Maximum - BoundsHeight);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int boundsHeight = 10;
|
||||||
|
public int BoundsHeight
|
||||||
|
{
|
||||||
|
get => boundsHeight;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
boundsHeight = value.CheckLowerLimit(1);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LeftButtonPos => 16;
|
||||||
|
|
||||||
|
public int RightButtonPos => Height - 16;
|
||||||
|
|
||||||
|
protected override void OnPaintFill(Graphics g, GraphicsPath path)
|
||||||
|
{
|
||||||
|
base.OnPaintFill(g, path);
|
||||||
|
g.Clear(fillColor);
|
||||||
|
|
||||||
|
DrawUpDownArrow(g, true);
|
||||||
|
DrawUpDownArrow(g, false);
|
||||||
|
DrawValueBar(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawValueBar(Graphics g)
|
||||||
|
{
|
||||||
|
Color clr = foreColor;
|
||||||
|
if (inCenterArea && IsPress)
|
||||||
|
{
|
||||||
|
clr = fillPressColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int top = 16 + Value * (Height - 32) / Maximum;
|
||||||
|
int height = BoundsHeight * (Height - 32) / Maximum;
|
||||||
|
|
||||||
|
g.SetHighQuality();
|
||||||
|
g.FillRoundRectangle(clr, new Rectangle(Width / 2 - 3, top, 6, height), 5);
|
||||||
|
g.SetDefaultQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rectangle GetUpRect()
|
||||||
|
{
|
||||||
|
var rect = new Rectangle(1, 1, Width - 2, 16);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rectangle GetDownRect()
|
||||||
|
{
|
||||||
|
var rect = new Rectangle(1, Height - 17, Width - 2, 16);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseDown(e);
|
||||||
|
IsPress = true;
|
||||||
|
|
||||||
|
if (inLeftArea)
|
||||||
|
{
|
||||||
|
int value = (Value - LargeChange).CheckRange(0, Maximum - BoundsHeight);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inRightArea)
|
||||||
|
{
|
||||||
|
int value = (Value + LargeChange).CheckRange(0, Maximum - BoundsHeight);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inCenterArea)
|
||||||
|
{
|
||||||
|
int y = BoundsHeight * (Height - 32) / Maximum;
|
||||||
|
int value = (e.Location.Y - y / 2) * maximum / (Height - 32);
|
||||||
|
value = value.CheckRange(0, Maximum - BoundsHeight);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseUp(e);
|
||||||
|
IsPress = false;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseLeave(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseLeave(e);
|
||||||
|
IsPress = false;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseEnter(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseEnter(e);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawUpDownArrow(Graphics g, bool isUp)
|
||||||
|
{
|
||||||
|
Color clr_arrow = foreColor;
|
||||||
|
if ((inLeftArea || inRightArea) && IsPress)
|
||||||
|
{
|
||||||
|
clr_arrow = fillPressColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
g.FillRectangle(fillColor, isUp ? GetUpRect() : GetDownRect());
|
||||||
|
g.SetHighQuality();
|
||||||
|
using (var pen = new Pen(clr_arrow, 2))
|
||||||
|
{
|
||||||
|
Point pt1, pt2, pt3;
|
||||||
|
if (!isUp)
|
||||||
|
{
|
||||||
|
pt1 = new Point(Width / 2 - 4, Height - 16 / 2 - 4);
|
||||||
|
pt2 = new Point(Width / 2, Height - 16 / 2);
|
||||||
|
pt3 = new Point(Width / 2 + 4, Height - 16 / 2 - 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pt1 = new Point(Width / 2 - 4, 16 / 2 + 4 - 1);
|
||||||
|
pt2 = new Point(Width / 2, 16 / 2 - 1);
|
||||||
|
pt3 = new Point(Width / 2 + 4, 16 / 2 + 4 - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.DrawLines(pen, new[] { pt1, pt2, pt3 });
|
||||||
|
}
|
||||||
|
|
||||||
|
g.SetDefaultQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool inLeftArea, inRightArea, inCenterArea;
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseMove(e);
|
||||||
|
inLeftArea = e.Location.Y < LeftButtonPos;
|
||||||
|
inRightArea = e.Location.Y > RightButtonPos;
|
||||||
|
inCenterArea = e.Location.Y >= LeftButtonPos && e.Location.Y <= RightButtonPos;
|
||||||
|
|
||||||
|
if (inCenterArea && IsPress)
|
||||||
|
{
|
||||||
|
int y = BoundsHeight * (Height - 32) / Maximum;
|
||||||
|
int value = (e.Location.Y - y / 2) * maximum / (Height - 32);
|
||||||
|
value = value.CheckRange(0, Maximum - BoundsHeight);
|
||||||
|
Value = value;
|
||||||
|
ValueChanged?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetStyleColor(UIBaseStyle uiColor)
|
||||||
|
{
|
||||||
|
base.SetStyleColor(uiColor);
|
||||||
|
if (uiColor.IsCustom()) return;
|
||||||
|
|
||||||
|
fillColor = uiColor.PlainColor;
|
||||||
|
foreColor = uiColor.ScrollBarForeColor;
|
||||||
|
fillHoverColor = uiColor.ButtonFillHoverColor;
|
||||||
|
fillPressColor = uiColor.ButtonFillPressColor;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 字体颜色
|
||||||
|
/// </summary>
|
||||||
|
[Description("字体颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
||||||
|
public override Color ForeColor
|
||||||
|
{
|
||||||
|
get => foreColor;
|
||||||
|
set => SetForeColor(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
||||||
|
/// </summary>
|
||||||
|
[Description("填充颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "235, 243, 255")]
|
||||||
|
public Color FillColor
|
||||||
|
{
|
||||||
|
get => fillColor;
|
||||||
|
set => SetFillColor(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Description("鼠标移上颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "111, 168, 255")]
|
||||||
|
public Color HoverColor
|
||||||
|
{
|
||||||
|
get => fillHoverColor;
|
||||||
|
set => SetFillHoveColor(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Description("鼠标按下颜色"), Category("SunnyUI")]
|
||||||
|
[DefaultValue(typeof(Color), "74, 131, 229")]
|
||||||
|
public Color PressColor
|
||||||
|
{
|
||||||
|
get => fillPressColor;
|
||||||
|
set => SetFillPressColor(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -116,6 +116,12 @@
|
|||||||
<Compile Include="Controls\UIHorScrollBar.cs">
|
<Compile Include="Controls\UIHorScrollBar.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Controls\UIVerScrollBarEx.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Controls\UIHorScrollBarEx.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Controls\UINavMenuHelper.cs" />
|
<Compile Include="Controls\UINavMenuHelper.cs" />
|
||||||
<Compile Include="Controls\UIPagination.cs">
|
<Compile Include="Controls\UIPagination.cs">
|
||||||
<SubType>UserControl</SubType>
|
<SubType>UserControl</SubType>
|
||||||
@ -189,7 +195,7 @@
|
|||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Controls\UITreeView.cs">
|
<Compile Include="Controls\UITreeView.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>UserControl</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Forms\UIStatusForm.cs">
|
<Compile Include="Forms\UIStatusForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user