作者: together
查看: 2173|回复: 0

请教CCWin.SkinControl.SkinComboBox 居中

[复制链接]
together 发表于 2017-7-28 10:27:25 | 显示全部楼层 |阅读模式
查看: 2173|回复: 0
请教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);
        }
也不生效
谢谢
回复 论坛版权

使用道具 举报

您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-4-17 05:17, Processed in 0.538405 second(s), 30 queries , Gzip On.

快速回复 返回顶部 返回列表