This is a fix for lack of dispose in OnPaint
protected override void OnPaint(PaintEventArgs e)
{
using (Graphics g = e.Graphics)
{
Pen pen_controlLightLight = new Pen(SystemColors.ControlLightLight);
Pen pen_controlLight = new Pen(SystemColors.ControlLight);
Pen pen_controlDark = new Pen(SystemColors.ControlDark);
Pen pen_backColor = new Pen(this.BackColor);
Pen pen_hotColor = new Pen(this.hotColor);
Pen pen_controlDarkDark = new Pen(SystemColors.ControlDarkDark);
Brush brush_controlDark = new SolidBrush(SystemColors.ControlDark);
Brush brush_controlDarkDark = new SolidBrush(SystemColors.ControlDarkDark);
Brush brush_backColor = new SolidBrush(this.BackColor);
Brush brush_hotColor = new SolidBrush(this.hotColor);
Rectangle r = this.ClientRectangle;
g.FillRectangle(brush_backColor, r);
#region Vertical Splitter
if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right)
{
rr = new Rectangle(r.X, (int)r.Y + ((r.Height - 115) / 2), 8, 115);
this.Width = 8;
if (hot)
{
g.FillRectangle(brush_hotColor, new Rectangle(rr.X + 1, rr.Y, 6, 115));
}
else
{
g.FillRectangle(brush_backColor, new Rectangle(rr.X + 1, rr.Y, 6, 115));
}
using (Pen pn = new Pen(SystemColors.ControlDark, 1))
{
g.DrawLine(pn, rr.X + 1, rr.Y, rr.X + rr.Width - 2, rr.Y);
g.DrawLine(pn, rr.X + 1, rr.Y + rr.Height, rr.X + rr.Width - 2, rr.Y + rr.Height);
}
if (this.Enabled)
{
g.FillPolygon(brush_controlDarkDark, ArrowPointArray(rr.X + 2, rr.Y + 3));
g.FillPolygon(brush_controlDarkDark, ArrowPointArray(rr.X + 2, rr.Y + rr.Height - 9));
}
int x = rr.X + 3;
int y = rr.Y + 14;
switch (visualStyle)
{
case VisualStyles.Mozilla:
for (int i = 0; i < 30; i++)
{
g.DrawLine(pen_controlLightLight, x, y + (i * 3), x + 1, y + 1 + (i * 3));
g.DrawLine(pen_controlDarkDark, x + 1, y + 1 + (i * 3), x + 2, y + 2 + (i * 3));
if (hot)
{
g.DrawLine(pen_hotColor, x + 2, y + 1 + (i * 3), x + 2, y + 2 + (i * 3));
}
else
{
g.DrawLine(pen_backColor, x + 2, y + 1 + (i * 3), x + 2, y + 2 + (i * 3));
}
}
break;
case VisualStyles.DoubleDots:
for (int i = 0; i < 30; i++)
{
g.DrawRectangle(pen_controlLightLight, x, y + 1 + (i * 3), 1, 1);
g.DrawRectangle(pen_controlDark, x - 1, y + (i * 3), 1, 1);
i++;
g.DrawRectangle(pen_controlLightLight, x + 2, y + 1 + (i * 3), 1, 1);
g.DrawRectangle(pen_controlDark, x + 1, y + (i * 3), 1, 1);
}
break;
case VisualStyles.Win9x:
g.DrawLine(pen_controlLightLight, x, y, x + 2, y);
g.DrawLine(pen_controlLightLight, x, y, x, y + 90);
g.DrawLine(pen_controlDark, x + 2, y, x + 2, y + 90);
g.DrawLine(pen_controlDark, x, y + 90, x + 2, y + 90);
break;
case VisualStyles.XP:
for (int i = 0; i < 18; i++)
{
g.DrawRectangle(pen_controlLight, x, y + (i * 5), 2, 2);
g.DrawRectangle(pen_controlLightLight, x + 1, y + 1 + (i * 5), 1, 1);
g.DrawRectangle(pen_controlDarkDark, x, y + (i * 5), 1, 1);
g.DrawLine(pen_controlDark, x, y + (i * 5), x, y + (i * 5) + 1);
g.DrawLine(pen_controlDark, x, y + (i * 5), x + 1, y + (i * 5));
}
break;
case VisualStyles.Lines:
for (int i = 0; i < 44; i++)
{
g.DrawLine(pen_controlDark, x, y + (i * 2), x + 2, y + (i * 2));
}
break;
}
if (this.borderStyle != System.Windows.Forms.Border3DStyle.Flat)
{
ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, this.borderStyle, Border3DSide.Left);
ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, this.borderStyle, Border3DSide.Right);
}
}
#endregion
#region Horizontal Splitter
else if (this.Dock == DockStyle.Top || this.Dock == DockStyle.Bottom)
{
rr = new Rectangle((int)r.X + ((r.Width - 115) / 2), r.Y, 115, 8);
this.Height = 8;
if (hot)
{
g.FillRectangle(brush_hotColor, new Rectangle(rr.X, rr.Y + 1, 115, 6));
}
else
{
g.FillRectangle(brush_backColor, new Rectangle(rr.X, rr.Y + 1, 115, 6));
}
using (Pen pn = new Pen(SystemColors.ControlDark, 1))
{
g.DrawLine(pn, rr.X, rr.Y + 1, rr.X, rr.Y + rr.Height - 2);
g.DrawLine(pn, rr.X + rr.Width, rr.Y + 1, rr.X + rr.Width, rr.Y + rr.Height - 2);
}
if (this.Enabled)
{
g.FillPolygon(brush_controlDarkDark, ArrowPointArray(rr.X + 3, rr.Y + 2));
g.FillPolygon(brush_controlDarkDark, ArrowPointArray(rr.X + rr.Width - 9, rr.Y + 2));
}
int x = rr.X + 14;
int y = rr.Y + 3;
switch (visualStyle)
{
case VisualStyles.Mozilla:
for (int i = 0; i < 30; i++)
{
g.DrawLine(pen_controlLightLight, x + (i * 3), y, x + 1 + (i * 3), y + 1);
g.DrawLine(pen_controlDarkDark, x + 1 + (i * 3), y + 1, x + 2 + (i * 3), y + 2);
if (hot)
{
g.DrawLine(pen_hotColor, x + 1 + (i * 3), y + 2, x + 2 + (i * 3), y + 2);
}
else
{
g.DrawLine(pen_backColor, x + 1 + (i * 3), y + 2, x + 2 + (i * 3), y + 2);
}
}
break;
case VisualStyles.DoubleDots:
for (int i = 0; i < 30; i++)
{
g.DrawRectangle(pen_controlLightLight, x + 1 + (i * 3), y, 1, 1);
g.DrawRectangle(pen_controlDark, x + (i * 3), y - 1, 1, 1);
i++;
g.DrawRectangle(pen_controlLightLight, x + 1 + (i * 3), y + 2, 1, 1);
g.DrawRectangle(pen_controlDark, x + (i * 3), y + 1, 1, 1);
}
break;
case VisualStyles.Win9x:
g.DrawLine(pen_controlLightLight, x, y, x, y + 2);
g.DrawLine(pen_controlLightLight, x, y, x + 88, y);
g.DrawLine(pen_controlDark, x, y + 2, x + 88, y + 2);
g.DrawLine(pen_controlDark, x + 88, y, x + 88, y + 2);
break;
case VisualStyles.XP:
for (int i = 0; i < 18; i++)
{
g.DrawRectangle(pen_controlLight, x + (i * 5), y, 2, 2);
g.DrawRectangle(pen_controlLightLight, x + 1 + (i * 5), y + 1, 1, 1);
g.DrawRectangle(pen_controlDarkDark, x + (i * 5), y, 1, 1);
g.DrawLine(pen_controlDark, x + (i * 5), y, x + (i * 5) + 1, y);
g.DrawLine(pen_controlDark, x + (i * 5), y, x + (i * 5), y + 1);
}
break;
case VisualStyles.Lines:
for (int i = 0; i < 44; i++)
{
g.DrawLine(pen_controlDark, x + (i * 2), y, x + (i * 2), y + 2);
}
break;
}
if (this.borderStyle != System.Windows.Forms.Border3DStyle.Flat)
{
ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, this.borderStyle, Border3DSide.Top);
ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, this.borderStyle, Border3DSide.Bottom);
}
}
#endregion
else
{
throw new Exception("The Collapsible Splitter control cannot have the Filled or None Dockstyle property");
}
pen_controlLightLight.Dispose();
pen_controlLight.Dispose();
pen_controlDark.Dispose();
pen_backColor.Dispose();
pen_hotColor.Dispose();
pen_controlDarkDark.Dispose();
brush_controlDark.Dispose();
brush_controlDarkDark.Dispose();
brush_backColor.Dispose();
brush_hotColor.Dispose();
}
}
|