This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyNavBarControl.cs
105 lines (99 loc) · 3.21 KB
/
MyNavBarControl.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using DevExpress.XtraNavBar;
namespace WindowsApplication1
{
public class MyNavBarControl : NavBarControl
{
private NavBarGroup NextGroup(NavBarGroup group, bool forward)
{
if (Groups.Count == 0) //|| (Groups.Count == 1 && group != null)
return null;
if (group == null)
return (forward) ? Groups[0] : Groups[Groups.Count - 1];
if (forward)
{
if (Groups.IndexOf(group) < Groups.Count - 1)
return Groups[Groups.IndexOf(group) + 1];
else
return Groups[0];
}
else if (Groups.IndexOf(group) > 0)
return Groups[Groups.IndexOf(group) - 1];
else
return Groups[Groups.Count - 1];
}
private NavBarItemLink FindNearItemLink(bool forward)
{
NavBarItemLink link = SelectedLink;
NavBarGroup group;
if (link == null)
group = NextGroup(null, forward);
else
group = link.Group;
if (group == null)
return null;
NavBarGroup startGroup = group;
int i;
if (link != null)
i = group.ItemLinks.IndexOf(link);
else
i = (forward) ? -1 : group.ItemLinks.Count;
bool repeat = false;
do
{
if (forward)
{
if (i < group.ItemLinks.Count - 1)
return group.ItemLinks[i + 1];
else
{
group = NextGroup(group, forward);
repeat = i > 0;
i = -1;
}
}
else
{
if (i > 0 && group.ItemLinks.Count > 0)
return group.ItemLinks[i - 1];
else
{
group = NextGroup(group, forward);
repeat = i < group.ItemLinks.Count - 1;
i = group.ItemLinks.Count;
}
}
}
while (group != startGroup || repeat);
return null;
}
public void SelectNextLink(bool forward)
{
SelectedLink = FindNearItemLink(forward);
if (SelectedLink != null && !SelectedLink.Group.Expanded)
SelectedLink.Group.Expanded = true;
ViewInfo.MakeLinkVisible(SelectedLink);
}
protected override bool ProcessDialogKey(Keys keyData)
{
Keys key = keyData & (~Keys.Modifiers);
switch (key)
{
case Keys.Down:
SelectNextLink(true);
break;
case Keys.Up:
SelectNextLink(false);
break;
default:
return base.ProcessDialogKey(keyData);
}
return false;
}
}
}