* UIDataGridView:更新了水平和垂直滚动条的显示,优化滚动效果。

This commit is contained in:
Sunny 2020-08-22 22:56:03 +08:00
parent f0a1cccd6c
commit 973db19102
4 changed files with 34 additions and 17 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,7 +29,7 @@ using System.Windows.Forms;
namespace Sunny.UI namespace Sunny.UI
{ {
public sealed 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 UIHorScrollBar HBar = new UIHorScrollBar();
@ -38,8 +38,8 @@ namespace Sunny.UI
{ {
BackgroundColor = UIColor.White; BackgroundColor = UIColor.White;
GridColor = UIColor.Blue; GridColor = UIColor.Blue;
Font = UIFontColor.Font; base.Font = UIFontColor.Font;
DoubleBuffered = true; base.DoubleBuffered = true;
VBar.Parent = this; VBar.Parent = this;
VBar.Visible = false; VBar.Visible = false;
@ -169,9 +169,9 @@ namespace Sunny.UI
return; return;
} }
if (VerticalScrollBar.Visible) if (RowCount > DisplayedRowCount(false))
{ {
VBar.Maximum = RowCount - this.Rows.GetRowCount(DataGridViewElementStates.Displayed) + 1; VBar.Maximum = RowCount - DisplayedRowCount(false);
VBar.Value = FirstDisplayedScrollingRowIndex; VBar.Value = FirstDisplayedScrollingRowIndex;
VBar.Visible = true; VBar.Visible = true;
} }
@ -180,9 +180,9 @@ namespace Sunny.UI
VBar.Visible = false; VBar.Visible = false;
} }
if (HorizontalScrollBar.Visible) if (ColumnCount > DisplayedColumnCount(false))
{ {
HBar.Maximum = VisibleColumnCount() - 1; HBar.Maximum = ColumnCount - DisplayedColumnCount(false);
HBar.Value = FirstDisplayedScrollingColumnIndex; HBar.Value = FirstDisplayedScrollingColumnIndex;
HBar.Visible = true; HBar.Visible = true;
} }
@ -242,17 +242,34 @@ namespace Sunny.UI
private void SetBarPosition() private void SetBarPosition()
{ {
VBar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 1; if (ShowRect)
VBar.Top = 0; {
VBar.Width = ScrollBarInfo.VerticalScrollBarWidth() + 1; VBar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 2;
VBar.Height = Height; VBar.Top = 1;
VBar.BringToFront(); VBar.Width = ScrollBarInfo.VerticalScrollBarWidth() + 1;
VBar.Height = Height - 2;
VBar.BringToFront();
HBar.Left = 0; HBar.Left = 2;
HBar.Height = ScrollBarInfo.HorizontalScrollBarHeight() + 1; HBar.Height = ScrollBarInfo.HorizontalScrollBarHeight() + 1;
HBar.Width = Width - (VBar.Visible ? VBar.Width : 0); HBar.Width = Width - (VBar.Visible ? VBar.Width : 0) - 2;
HBar.Top = Height - HBar.Height; HBar.Top = Height - HBar.Height - 2;
HBar.BringToFront(); HBar.BringToFront();
}
else
{
VBar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 1;
VBar.Top = 0;
VBar.Width = ScrollBarInfo.VerticalScrollBarWidth() + 1;
VBar.Height = Height;
VBar.BringToFront();
HBar.Left = 0;
HBar.Height = ScrollBarInfo.HorizontalScrollBarHeight() + 1;
HBar.Width = Width - (VBar.Visible ? VBar.Width : 0);
HBar.Top = Height - HBar.Height;
HBar.BringToFront();
}
} }
protected override void OnColumnAdded(DataGridViewColumnEventArgs e) protected override void OnColumnAdded(DataGridViewColumnEventArgs e)