-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewerForm.cs
109 lines (103 loc) · 4.74 KB
/
ViewerForm.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
106
107
108
109
using DevExpress.DashboardCommon;
using DevExpress.DashboardWin;
using DevExpress.XtraEditors;
using System.Linq;
using System.Windows.Forms;
namespace DashboardNextPrevTab
{
public partial class ViewerForm : XtraForm {
const int slideShowIntervalInMilliseconds = 3000;
Timer slideShowTimer = new Timer();
TabContainerDashboardItem TabContainer {
get {
Dashboard dashboard = dashboardViewer.Dashboard;
return dashboard.Items.SingleOrDefault(i => i is TabContainerDashboardItem) as TabContainerDashboardItem;
}
}
public ViewerForm() {
InitializeComponent();
dashboardViewer.CustomizeDashboardTitle += DashboardViewerCustomizeDashboardTitle;
dashboardViewer.SelectedTabPageChanged += DashboardViewerSelectedTabPageChanged;
dashboardViewer.UpdateDashboardTitle();
SetUpTimer();
}
void SetUpTimer() {
slideShowTimer.Interval = slideShowIntervalInMilliseconds;
slideShowTimer.Tick += SlideShowTimerTick;
}
void DashboardViewerCustomizeDashboardTitle(object sender, CustomizeDashboardTitleEventArgs e) {
DashboardToolbarItem nextTabItem = new DashboardToolbarItem("Next tab", NextPrevTabItemClick);
nextTabItem.Tag = NextPrevValue.Next;
nextTabItem.SvgImage = imageCollection["Next"];
e.Items.Insert(0, nextTabItem);
DashboardToolbarItem prevTabItem = new DashboardToolbarItem("Previous tab", NextPrevTabItemClick);
prevTabItem.Tag = NextPrevValue.Prev;
prevTabItem.SvgImage = imageCollection["Prev"];
e.Items.Insert(0, prevTabItem);
DashboardToolbarItem showTabHederItem = new DashboardToolbarItem(TabContainer.ShowCaption, "Show tab headers", ShowHideTabHeadersItemClick);
showTabHederItem.SvgImage = imageCollection["ShowCaption"];
e.Items.Insert(0, showTabHederItem);
DashboardToolbarItem slideShowItem = new DashboardToolbarItem(slideShowTimer.Enabled, "Slideshow", SlideShowItemClick);
slideShowItem.SvgImage = imageCollection["Slideshow"];
e.Items.Insert(0, slideShowItem);
}
void SlideShowTimerTick(object sender, System.EventArgs e) {
transitionManager.StartTransition(dashboardViewer);
try {
ShowNextPrevTab(NextPrevValue.Next);
} finally {
transitionManager.EndTransition();
}
}
void ShowNextPrevTab(NextPrevValue value) {
TabContainerDashboardItem tabContainer = TabContainer;
if(tabContainer != null) {
int increment = value == NextPrevValue.Next ? 1 : -1;
string tabContainerName = tabContainer.ComponentName;
int selectedIndex = dashboardViewer.GetSelectedTabPageIndex(tabContainerName);
int pageCount = tabContainer.TabPages.Count;
dashboardViewer.SetSelectedTabPage(tabContainerName, (selectedIndex + pageCount + increment) % pageCount);
}
}
void NextPrevTabItemClick(DashboardToolbarItemClickEventArgs args) {
ShowNextPrevTab((NextPrevValue)args.Item.Tag);
}
void SlideShowItemClick(DashboardToolbarItemClickEventArgs args) {
if(args.Item.Checked.HasValue && args.Item.Checked.Value)
slideShowTimer.Start();
else
slideShowTimer.Stop();
}
void ShowHideTabHeadersItemClick(DashboardToolbarItemClickEventArgs args) {
TabContainerDashboardItem tabContainer = TabContainer;
if(tabContainer != null) {
if(args.Item.Checked.HasValue && args.Item.Checked.Value) {
tabContainer.ShowCaption = true;
} else {
tabContainer.ShowCaption = false;
}
}
}
void DashboardViewerSelectedTabPageChanged(object sender, SelectedTabPageChangedEventArgs e) {
TabContainerDashboardItem tabContainer = TabContainer;
if(tabContainer != null && !tabContainer.ShowCaption) {
string selectedTabPageName = e.Page;
dashboardViewer.Dashboard.Title.Text = TabContainer.TabPages[selectedTabPageName].Name;
}
}
protected override void Dispose(bool disposing) {
if(disposing && (components != null)) {
components.Dispose();
}
if(disposing) {
slideShowTimer.Tick -= SlideShowTimerTick;
slideShowTimer.Dispose();
}
base.Dispose(disposing);
}
}
enum NextPrevValue {
Next,
Prev
}
}