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