Позволяет переключаться между несколькими панелями, например, в меню настроек Вашей программы, как в режиме выполнения программы, так и в режиме разработки (во время работы над формой в конструкторе Visual Studio)
C# | 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
110
111
112
| using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
namespace FSImark.Controls
{
[Designer(typeof(PanelPageControlDesigner))]
public class PanelPageControl : Panel
{
private Panel[] panelPages;
private int selectedIndex;
private Panel selectedPanel;
[Category("PanelPageControl")]
[Description("Displayed panel")]
[Editor(typeof(PanelPageSelectorEditor), typeof(UITypeEditor))]
public Panel SelectedPanel
{
get
{
if (PanelPages != null) return selectedPanel;
return null;
}
set
{
selectedIndex = GetIndexFromPanel(value);
SelectPanel(value);
}
}
[Category("PanelPageControl")]
[Description("PanelPage Collection")]
public Panel[] PanelPages
{
get { return panelPages; }
set
{
if (value != null)
{
panelPages = value;
if (panelPages.Length > 0 && selectedIndex < 0)
{
selectedIndex = 0;
selectedPanel = value[selectedIndex];
SelectPanel(selectedPanel);
}
}
}
}
[Category("PanelPageControl")]
[Description("Index of selected page")]
public int SelectedIndex
{
get
{
if (PanelPages == null) return -1;
return selectedIndex;
}
set
{
if (PanelPages != null && PanelPages.Length > 0)
{
if (value < 0 || value > PanelPages.Length - 1) throw new ArgumentException(nameof(SelectedIndex));
selectedIndex = value;
SelectPanel(PanelPages[value]);
}
}
}
public event EventHandler SelectionChanged = delegate { };
protected override void OnControlAdded(ControlEventArgs e) { }
private void SelectPanel(Panel selectingPanel)
{
if (selectingPanel == selectedPanel) return;
Controls.Remove(selectedPanel);
selectedPanel = selectingPanel;
Controls.Add(selectedPanel);
if (selectedPanel.Dock != DockStyle.Fill)
selectedPanel.Dock = DockStyle.Fill;
SelectionChanged(this, EventArgs.Empty);
}
private int GetIndexFromPanel(Panel panel)
{
if (PanelPages == null) return -1;
for (int index = 0; index < PanelPages.Length; index++)
if (panel == PanelPages[index]) return index;
return -1;
}
protected override void Dispose(bool disposing)
{
if (PanelPages != null)
foreach (Panel page in PanelPages)
page.Dispose();
base.Dispose(disposing);
}
}
} |
|
Проект с тремя вариантами выбора отображаемой панели:
PanelPageControlForm.rar |