C# winfrom ComboBox 调整下拉菜单的高度


1.设置属性

            // 1、属性设置 DrawMode ->OwnerDrawVariable
            this.cboBoxPostID.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
            this.cboBoxPostID.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.cboBoxPostID_DrawItem);

2.DrawItem事件

     private void cboBoxPostID_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            e.DrawBackground();
            e.DrawFocusRectangle();
            e.Graphics.DrawString(cboBoxPostID.GetItemText(cboBoxPostID.Items[e.Index]).ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 3);
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM