-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnTabControlDesigner.cs
142 lines (119 loc) · 3.28 KB
/
cnTabControlDesigner.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Created by SharpDevelop.
* User: Ñåðãåé
* Date: 21.11.2006
* Time: 1:15
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design;
namespace ComponentsNET
{
public class cnTabControlDesigner : System.Windows.Forms.Design.ParentControlDesigner
{
private DesignerVerb verbRemovePage;
private IDesignerHost host = null;
private ISelectionService selService = null;
private cnTabControl TabControl
{
get
{
return this.Control as cnTabControl;
}
}
private IDesignerHost DesignerHost
{
get
{
if( host == null )
host = (IDesignerHost)GetService(typeof(IDesignerHost));
return host;
}
}
public ISelectionService SelectionService
{
get
{
if(selService == null)
selService = (ISelectionService)GetService(typeof(ISelectionService));
return selService;
}
}
public override DesignerVerbCollection Verbs
{
get
{
DesignerVerbCollection v = new DesignerVerbCollection();
v.Add(new DesignerVerb("&Add Page", new EventHandler(AddPage)) );
v.Add(verbRemovePage = new DesignerVerb("&Remove Page", new EventHandler(RemovePage)));
verbRemovePage.Enabled = TabControl.TabPages.Count > 0;
return v;
}
}
private void AddPage(object sender, System.EventArgs e)
{
if (DesignerHost != null)
{
IComponent c = DesignerHost.CreateComponent(typeof(ComponentsNET.cnTabPage));
TabControl.TabPages.Add(c as cnTabPage);
verbRemovePage.Enabled = true;
}
}
private void RemovePage(object sender, System.EventArgs e)
{
if (DesignerHost != null)
{
DesignerHost.DestroyComponent(TabControl.TabPages[TabControl.SelectedIndex]);
TabControl.TabPages.RemoveAt(TabControl.SelectedIndex);
verbRemovePage.Enabled = TabControl.TabPages.Count > 0;
}
}
protected override bool GetHitTest(Point p)
{
Point cp = TabControl.PointToClient(p);
return TabControl.GetHitTest(cp.X, cp.Y) >= 0;
}
private void CurrentPageChanged(cnTabControl sender, cnTabPage page)
{
if (SelectionService != null)
{
System.Collections.ArrayList s = new System.Collections.ArrayList();
s.Add(TabControl.TabPages[TabControl.SelectedIndex]);
SelectionService.SetSelectedComponents(s);
}
}
public override void Initialize(IComponent component)
{
base.Initialize(component);
this.DrawGrid = false;
if (TabControl != null)
TabControl.SelectPage += new cnTabControl.SelectEventHandler(CurrentPageChanged);
}
protected override void Dispose(bool disposing)
{
if( disposing )
{
TabControl.SelectPage -= new cnTabControl.SelectEventHandler(CurrentPageChanged);
}
base.Dispose( disposing );
}
}
public class cnTabPageDesigner : System.Windows.Forms.Design.ParentControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);
this.DrawGrid = true;
}
public override System.Windows.Forms.Design.SelectionRules SelectionRules
{
get
{
return System.Windows.Forms.Design.SelectionRules.Locked;
}
}
}
}