반응형
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Duzon.ReportDesigner.Components.Dialog
{
public class LineStyleComboBox : ComboBox, ISupportInitialize
{
private bool _itemsAreSetup = false;
public LineStyleComboBox()
{
this.DropDownStyle = ComboBoxStyle.DropDownList;
this.DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (e.Index > -1)
{
int startX = e.Bounds.Left + 5;
int startY = (e.Bounds.Y + e.Bounds.Height / 2);
int endX = e.Bounds.Right - 5;
int endY = (e.Bounds.Y + e.Bounds.Height / 2);
using (Pen p = new Pen(Color.Black,2))
{
DashStyle index = (DashStyle)this.Items[e.Index];
switch (index)
{
case DashStyle.Solid:
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
break;
case DashStyle.Dash:
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
break;
case DashStyle.DashDot:
p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
break;
case DashStyle.DashDotDot:
p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
break;
case DashStyle.Dot:
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
break;
default:
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
break;
}
e.Graphics.DrawLine(p, new Point(startX, startY), new Point(endX, endY));
}
}
base.OnDrawItem(e);
}
#region ISupportInitialize 멤버
public void BeginInit()
{
}
public void EndInit()
{
Items.Clear();
SetItem();
_itemsAreSetup = true;
}
private void SetItem()
{
if (_itemsAreSetup)
return;
foreach (object gItem in Enum.GetValues(typeof(DashStyle)))
{
if ((DashStyle)gItem != DashStyle.Custom)
this.Items.Add(gItem);
}
}
#endregion
}
}
//codeEnd
'Programing > C# ' 카테고리의 다른 글
c# 코드 관리자 권한으로 실행 (0) | 2012.11.06 |
---|---|
네트워크 드라이브 목록 가져오기 (0) | 2012.09.24 |
ColorComboBox 만들기 (0) | 2012.06.21 |
Color이름으로 Color객체 얻어오기 (0) | 2012.06.21 |
ComboBox in ListView (ListView에서 ComboBox띄우기) (0) | 2012.06.14 |