WEB开发网
开发学院软件开发C语言 C#仿QQ皮肤-ComboBox 控件实现 阅读

C#仿QQ皮肤-ComboBox 控件实现

 2010-09-30 22:44:29 来源:WEB开发网   
核心提示: 还有一个更重的方法就是OnDrawItem方法这是在加载时绘制一下初始化的效果protectedoverridevoidOnDrawItem(DrawItemEventArgse){Graphicsg=e.Graphics;//绘制区域Rectangler=e.Bounds;Fontfn=nul

还有一个更重的方法就是OnDrawItem方法这是在加载时绘制一下初始化的效果

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;
            //绘制区域
            Rectangle r = e.Bounds;
            Font fn = null;
            if (e.Index >= 0)
            {
                if (e.State == DrawItemState.None)
                {
                    //设置字体、字符串格式、对齐方式
                    fn = e.Font;
                    string s = this.Items[e.Index].ToString ();
                    StringFormat sf = new StringFormat();
                    sf.Alignment = StringAlignment.Near;
                    //根据不同的状态用不同的颜色表示
                    if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
                    {
                        e.Graphics.FillRectangle(new SolidBrush(Color.Red), r);
                        e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black), r, sf);
                        e.DrawFocusRectangle();
                    }
                    else
                    {
                        e.Graphics.FillRectangle(new SolidBrush(Color.White), r);
                        e.Graphics.DrawString(s, fn, new SolidBrush(Shared.FontColor), r, sf);
                        e.DrawFocusRectangle();
                    }
                }
                else
                {
                    fn = e.Font;
                    StringFormat sf = new StringFormat();
                    sf.Alignment = StringAlignment.Near;
                    string s = this.Items[e.Index].ToString ();
                    e.Graphics.FillRectangle(new SolidBrush(Shared.ControlBackColor), r);
                    e.Graphics.DrawString(s, fn, new SolidBrush(Shared.FontColor), r, sf);
                    
                }
            }
        }

上一页  1 2 3 4 5 6 7  下一页

Tags:QQ 皮肤 ComboBox

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接