作者: together
查看: 2183|回复: 0
打印 上一主题 下一主题

请教CCWin.SkinControl.SkinComboBox 居中

[复制链接]
跳转到指定楼层
楼主
together 发表于 2017-7-28 10:27:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
查看: 2183|回复: 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);
        }
也不生效
谢谢
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播
回复 论坛版权

使用道具 举报

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

本版积分规则

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

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-5-8 15:47, Processed in 0.544276 second(s), 29 queries , Gzip On.

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