放大comboBox列表框行间距

来源:互联网 发布:linux怎么退出sqlplus 编辑:程序博客网 时间:2024/05/19 17:27
public static void Bind(ComboBox cbox, int itemHeight)        {            cbox.DropDownStyle = ComboBoxStyle.DropDownList;            cbox.ItemHeight = itemHeight; cbox.DrawMode = DrawMode.OwnerDrawFixed;            cbox.DrawItem += new DrawItemEventHandler(delegate(object sender, DrawItemEventArgs e)            {                if (e.Index < 0)                 {                     return;                }                 e.DrawBackground();                 e.DrawFocusRectangle();                                //文本格式垂直居中方法1                float difH = (e.Bounds.Height - e.Font.Height) / 2;                RectangleF rf = new RectangleF(e.Bounds.X, e.Bounds.Y + difH, e.Bounds.Width, e.Font.Height);                e.Graphics.DrawString(cbox.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), rf);
//文本格式垂直居中方法2           StringFormat strFormat = new StringFormat();            strFormat.LineAlignment = StringAlignment.Center;            e.Graphics.DrawString(itemText, new Font("宋体", 12), Brushes.Black, textRect, strFormat);
}); }


参考自:http://www.cftea.com/c/2012/11/5663.asp

0 0
原创粉丝点击