combobox文本居中。。高手指教。

解决方案 »

  1.   

    你可以自己写一个combobox继承于Combobox
      

  2.   

     private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
            {
                string s = this.comboBox1.Items[e.Index].ToString();
                SizeF ss = e.Graphics.MeasureString(s, e.Font);            float l = (float)(e.Bounds.Width - ss.Width) / 2;
                if (l < 0) l = 0f;
                float t = (float)(e.Bounds.Height - ss.Height) / 2;
                if (t < 0) t = 0f;
                t = t + this.comboBox1.ItemHeight*e.Index;
                e.DrawBackground();
                e.DrawFocusRectangle();  
                e.Graphics.DrawString(s, e.Font, new SolidBrush(e.ForeColor), l, t);
            }
    设置:
     this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;