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);
放大comboBox列表框行间距
最新推荐文章于 2024-03-08 17:25:14 发布