请教CCWin.SkinControl.SkinComboBox 居中 是否支持居中?
我自己设置
将ComboBox.DrawMode设置为DrawMode.OwnerDrawFixed,
对ComboBox的DrawItem事件编程,各个项目居中显示。
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 left = (float)(e.Bounds.Width - ss.Width) / 2;
if (left < 0) left = 0f;
float top = (float)(e.Bounds.Height - ss.Height) / 2;
// 垂直居中
if (top < 0) top = 0f;
top = top + this.comboBox1.ItemHeight * e.Index;
// 输出
e.DrawBackground();
e.DrawFocusRectangle();
e.Graphics.DrawString(
s,
e.Font,
new SolidBrush(e.ForeColor),
left, top);
}
也不生效 谢谢 |