반응형
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

+ Recent posts