MTSplitter.cs
8.5 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
* Proje : MT Ortak kütüphane
*
* Hazırlayan : Muhammed ŞAHİN
* eMail : muhammed.sahin@gmail.com
*
* Açıklama : Splitter nesnesi içerisinde dock durumuna bakılarak
* ayıraç karakteri ve 3D görünüm veriliyor.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Windows.Forms;
namespace MT.WindowsUI
{
/// <summary>
/// Splitter, üzerinde ayıraç resmi çizili
/// </summary>
[ToolboxItem(true)]
[ToolboxBitmap(typeof(System.Windows.Forms.Splitter))]
[Description("3D Splitter")]
public class MTSplitter : Splitter
{
#region SplitterLightColor
private Color splitterLightColor = ProfessionalColors.SeparatorLight;
/// <summary>
/// Get/Set, Splitter için açık renk
/// </summary>
[Browsable(true)]
[Description("Splitter için açık renk")]
[Category("MT Kontrol")]
[DefaultValue(typeof(Color), "ProfessionalColors.SeparatorLight")]
public Color SplitterLightColor
{
get { return splitterLightColor; }
set
{
splitterLightColor = value;
this.Invalidate();
}
}
#endregion
#region SplitterDarkColor
private Color splitterDarkColor = ProfessionalColors.SeparatorDark;
/// <summary>
/// Get/Set, Splitter için koyu renk
/// </summary>
[Browsable(true)]
[Description("Splitter için koyu renk")]
[Category("MT Kontrol")]
[DefaultValue(typeof(Color), "ProfessionalColors.SeparatorDark")]
public Color SplitterDarkColor
{
get { return splitterDarkColor; }
set
{
splitterDarkColor = value;
this.Invalidate();
}
}
#endregion
#region SplitterBorderColor
private Color splitterBorderColor = Color.Transparent;
/// <summary>
/// Get/Set, Splitter için koyu renk
/// </summary>
[Browsable(true)]
[Description("Splitter dış çizgi rengi")]
[Category("MT Kontrol")]
[DefaultValue(typeof(Color), "ProfessionalColors.SeparatorDark")]
public Color SplitterBorderColor
{
get { return splitterBorderColor; }
set
{
splitterBorderColor = value;
this.Invalidate();
}
}
#endregion
#region SplitterPointCount
int splitterPointCount = 5;
/// <summary>
/// Ayıraç üzerinde gösterilen nokta sayısı
/// </summary>
[Browsable(true)]
[Description("Splitter içerisindeki nokta sayısı")]
[Category("MT Kontrol")]
[DefaultValue(5)]
public int SplitterPointCount
{
get { return splitterPointCount; }
set
{
splitterPointCount = value;
this.Invalidate();
}
}
#endregion
#region PaintAngle
private float splitterPaintAngle = 90F;
/// <summary>
/// Get/Set, Splitter boyama açısı
/// </summary>
[Browsable(true)]
[Description("Splitter boyama açısı")]
[Category("MT Kontrol")]
public float SplitterPaintAngle
{
get { return splitterPaintAngle; }
set
{
splitterPaintAngle = value;
this.Invalidate();
}
}
#endregion
#region Yapıcı Metodlar
public MTSplitter()
{
this.Size = new Size(4, 100);
this.SetCursorStyle();
// DockStyle değiştirildiğinde
this.DockChanged += delegate
{
this.SetCursorStyle();
};
// Sistem renkleri değiştirildiğinde
this.SystemColorsChanged += delegate
{
this.SplitterDarkColor = ProfessionalColors.SeparatorDark;
this.SplitterLightColor = ProfessionalColors.SeparatorLight;
};
// Tekrar boyutlandırıldığında
this.Resize += delegate(object sender, EventArgs e)
{
this.Invalidate();
};
}
void SetCursorStyle()
{
// Cursor Dock duruma göre değiştir
if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right) // Dik durumda ise
Cursor = Cursors.SizeWE;
else if (this.Dock == DockStyle.Bottom || this.Dock == DockStyle.Top) // Yatay durumda ise
Cursor = Cursors.SizeNS;
else
Cursor = Cursors.Default; // Kaplamış yada hiçbiri ise
}
#endregion
#region OnPaintBackground : Splitter için ayıraç çizgisi oluşturma
/// <summary>
/// Splitter için nokta işaretlerini oluştur
/// </summary>
/// <param name="pevent"></param>
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
Rectangle splitRectangle = this.ClientRectangle;
if (!(splitRectangle.Width > 0 && splitRectangle.Height > 0))
return;
// Ters renk splitter içerisinde gözükmesi için
Brush koyuRenk = new SolidBrush(this.SplitterDarkColor);
Brush acikRenk = new SolidBrush(this.SplitterLightColor);
// Eğer splitter dikey konumda ise
// Not : Splitter nesnesi DockStyle.Fill yada DockStyle.None değerlerini almıyor
if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right) // Dikey konumda ise
{
// Splitter 3D görünümü ver
using (Brush b = new LinearGradientBrush(splitRectangle, this.SplitterLightColor, this.SplitterDarkColor, this.SplitterPaintAngle))
{
pevent.Graphics.FillRectangle(b, splitRectangle);
}
int noktaBoyut = 5, noktaYukseklik = 2;
int ilkNoktaKoor = (splitRectangle.Height - (this.SplitterPointCount * noktaBoyut)) / 2;
int noktaLeft = (int)(this.Width / 2);
// Kareleri oluştur
for (int i = 0; i < this.SplitterPointCount; i++)
{
// Noktanın koyu rengi
pevent.Graphics.FillRectangle(koyuRenk, noktaLeft, ilkNoktaKoor, noktaYukseklik, noktaYukseklik);
// Noktanın açık rengi
pevent.Graphics.FillRectangle(acikRenk, noktaLeft, ilkNoktaKoor + 1, noktaYukseklik, noktaYukseklik);
// Siyah Nokta
pevent.Graphics.FillRectangle(SystemBrushes.GrayText, noktaLeft, ilkNoktaKoor - 1, noktaYukseklik, noktaYukseklik);
ilkNoktaKoor += noktaBoyut;
}
}
else if (this.Dock == DockStyle.Bottom || this.Dock == DockStyle.Top) // Eğer splitter yatay durumda ise
{
using (Brush b = new LinearGradientBrush(splitRectangle, this.SplitterLightColor, this.SplitterDarkColor, this.SplitterPaintAngle))
{
pevent.Graphics.FillRectangle(b, splitRectangle);
}
int noktaBoyut = 4, noktaYukseklik = 2;
int ilkNoktaKoor = (splitRectangle.Width - (this.SplitterPointCount * noktaBoyut)) / 2;
int Y = (int)((splitRectangle.Height - 1) / 2);
// Kareleri oluştur
for (int i = 0; i < this.SplitterPointCount; i++)
{
pevent.Graphics.FillRectangle(koyuRenk, ilkNoktaKoor, Y, noktaYukseklik, noktaYukseklik);
pevent.Graphics.FillRectangle(acikRenk, ilkNoktaKoor + 1, Y + 1, noktaYukseklik, noktaYukseklik);
pevent.Graphics.FillRectangle(SystemBrushes.GrayText, ilkNoktaKoor + 1, Y, noktaYukseklik, noktaYukseklik);
ilkNoktaKoor += noktaBoyut;
}
}
pevent.Graphics.DrawRectangle(new Pen(this.SplitterBorderColor),
new Rectangle(0, 0, Width - 1, Height));
if (koyuRenk is IDisposable)
koyuRenk.Dispose();
if (acikRenk is IDisposable)
acikRenk.Dispose();
}
#endregion
}
}