106 lines
2.9 KiB
C#
106 lines
2.9 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class BorderListBox : ListBox
|
|
{
|
|
#region Properties
|
|
public GridLinePattern SelectedLinePattern
|
|
{
|
|
get { return (Items[SelectedIndex] as GridLBItem).LinePattern; }
|
|
}
|
|
#endregion
|
|
#region ctor
|
|
public BorderListBox()
|
|
{
|
|
InitializeComponent();
|
|
SetupOptions();
|
|
}
|
|
public BorderListBox(IContainer container)
|
|
{
|
|
container.Add(this);
|
|
InitializeComponent();
|
|
SetupOptions();
|
|
}
|
|
private void SetupOptions()
|
|
{
|
|
this.DrawMode = DrawMode.OwnerDrawFixed;
|
|
//this.Font.Size;
|
|
DrawItem += new DrawItemEventHandler(BorderListBox_DrawItem);
|
|
//MeasureItem += new MeasureItemEventHandler(BorderListBox_MeasureItem);
|
|
Items.Add(new GridLBItem( GridLinePattern.None ));
|
|
Items.Add(new GridLBItem(GridLinePattern.Single));
|
|
Items.Add(new GridLBItem(GridLinePattern.Double));
|
|
Items.Add(new GridLBItem(GridLinePattern.Thick));
|
|
Items.Add(new GridLBItem(GridLinePattern.Dashed));
|
|
Items.Add(new GridLBItem(GridLinePattern.Dotted));
|
|
SelectedIndex = 1;
|
|
}
|
|
#endregion
|
|
#region Event Handlers
|
|
void BorderListBox_MeasureItem(object sender, MeasureItemEventArgs e)
|
|
{
|
|
e.ItemHeight = 22;
|
|
}
|
|
void BorderListBox_DrawItem(object sender, DrawItemEventArgs e)
|
|
{
|
|
e.DrawBackground();
|
|
e.DrawFocusRectangle();
|
|
int y = (e.Bounds.Top + e.Bounds.Bottom) / 2;
|
|
GridLBItem myGridLBItem = Items[e.Index] as GridLBItem;
|
|
Brush myBrush = new SolidBrush(e.ForeColor);
|
|
e.Graphics.DrawString(myGridLBItem.LinePattern.ToString(), Font, myBrush, e.Bounds);
|
|
Pen pn = VlnBorders.LinePen(myGridLBItem.LinePattern, e.ForeColor);
|
|
int leftMargin = 50;
|
|
int rightMargin = 4;
|
|
switch (myGridLBItem.LinePattern)
|
|
{
|
|
case GridLinePattern.Double:
|
|
e.Graphics.DrawLine(pn, e.Bounds.Left + leftMargin, y + 1, e.Bounds.Right - rightMargin, y + 1);
|
|
e.Graphics.DrawLine(pn, e.Bounds.Left + leftMargin, y - 1, e.Bounds.Right - rightMargin, y - 1);
|
|
break;
|
|
case GridLinePattern.None:
|
|
break;
|
|
case GridLinePattern.Single:
|
|
case GridLinePattern.Thick:
|
|
case GridLinePattern.Dotted:
|
|
case GridLinePattern.Dashed:
|
|
case GridLinePattern.Mixed:
|
|
default:
|
|
e.Graphics.DrawLine(pn, e.Bounds.Left + leftMargin, y, e.Bounds.Right - rightMargin, y);
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
public class GridLBItem
|
|
{
|
|
#region Properties
|
|
private GridLinePattern _LinePattern;
|
|
public GridLinePattern LinePattern
|
|
{
|
|
get { return _LinePattern; }
|
|
set { _LinePattern = value; }
|
|
}
|
|
#endregion
|
|
#region ctor
|
|
public GridLBItem(GridLinePattern linePattern)
|
|
{
|
|
LinePattern = linePattern;
|
|
}
|
|
#endregion
|
|
#region Public Methods
|
|
public override string ToString()
|
|
{
|
|
return LinePattern.ToString();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|