Repository navigation
Expand file tree
/
Copy pathTabNavigationDataGridView.cs
More file actions
74 lines (65 loc) · 3.12 KB
/
Copy pathTabNavigationDataGridView.cs
File metadata and controls
74 lines (65 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Semantic Anchor: Grid keyboard navigation; keep appearance controlled by ModernTheme.
// Arrow keys cannot transfer selection between cells; Tab/Shift+Tab retain standard navigation.
// Home/End remain available to an active text editing control.
using System.Windows.Forms;
// Semantic Anchor [TabNavigationDataGridView.cs]: Keyboard navigation overrides only intended grid navigation keys; preserve standard DataGridView editing and selection behavior.
namespace EasyVersionBackup
{
internal sealed class TabNavigationDataGridView : DataGridView
{
// Semantic Anchor [Atomic grid repaint]: The animated form backdrop and all
// DataGridView cells (including text, headers and vacant area) must be drawn
// into the same WinForms back buffer before the frame reaches the screen.
// This does not change cell selection, editing, events or default-theme colors.
public TabNavigationDataGridView()
{
DoubleBuffered = true;
}
// Semantic Anchor [Grid vacant backdrop]: The area below existing rows is not a
// data cell; paint only that vacant region to avoid covering editors or selection.
// Cell backgrounds are composited by Form1's existing CellPainting handler.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (VisualThemeRuntime.ActiveId == "Default") return;
int bottom = ColumnHeadersHeight;
foreach (DataGridViewRow row in Rows)
{
if (!row.Visible) continue;
var bounds = GetRowDisplayRectangle(row.Index, false);
if (bounds.Height > 0) bottom = System.Math.Max(bottom, bounds.Bottom);
if (bottom >= ClientSize.Height) return;
}
if (bottom >= ClientSize.Height) return;
var vacant = new System.Drawing.Rectangle(0, bottom,
ClientSize.Width, ClientSize.Height - bottom);
ModernWindowFrame.PaintThemeSurface(this, e.Graphics, vacant,
ModernTheme.WindowBackColor, ModernTheme.ThemeGridEmptyBackdropOpacity);
}
private static bool IsNavigationArrow(Keys keyData)
{
Keys key = keyData & Keys.KeyCode;
return key == Keys.Left || key == Keys.Right ||
key == Keys.Up || key == Keys.Down ||
key == Keys.Home || key == Keys.End;
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (IsNavigationArrow(keyData) && !(IsCurrentCellInEditMode &&
((keyData & Keys.KeyCode) == Keys.Home || (keyData & Keys.KeyCode) == Keys.End)))
{
return true;
}
return base.ProcessDialogKey(keyData);
}
protected override bool ProcessDataGridViewKey(KeyEventArgs e)
{
if (IsNavigationArrow(e.KeyData) && !(IsCurrentCellInEditMode &&
(e.KeyCode == Keys.Home || e.KeyCode == Keys.End)))
{
return true;
}
return base.ProcessDataGridViewKey(e);
}
}
}