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; } public void SetupFontAndSize(int fontSize) { Font = new Font(Font.FontFamily, fontSize, Font.Style); using (Graphics gr = CreateGraphics()) { SizeF mySize = gr.MeasureString("Almg", Font); ItemHeight = (int)Math.Ceiling(mySize.Height); } int newHeight = Items.Count * ItemHeight + 4; Size = new Size(newHeight, newHeight); } #endregion #region Event Handlers //void BorderListBox_MeasureItem(object sender, MeasureItemEventArgs e) //{ // e.ItemHeight = 22; //} private int _MaxLabelWidth = 0; private int MaxLabelWidth(Graphics gr) { if(_MaxLabelWidth == 0) { for(int i=0;i