C#中的右对齐组合框 [英] Right justified combobox in C#

查看:39
本文介绍了C#中的右对齐组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,C# 组合框中的项目是左对齐的.除了覆盖 DrawItem 方法和设置组合框 drawmode --> DrawMode.OwnerDrawFixed 之外,是否有任何选项可用于更改此理由?

By default the items in the C# Combobox are left aligned. Are there any options available to change this justification apart from overriding DrawItem method and setting the combobox drawmode --> DrawMode.OwnerDrawFixed?

干杯

推荐答案

如果你不介意另一边的 drop 小部件,你可以将控件样式设置为 RightToLeft = RightToLeft.Yes

You could just set the control style to RightToLeft = RightToLeft.Yes if you don't mind the drop widget on the other side as well.

设置 DrawMode = OwnerDrawFixed; 并钩住 DrawItem 事件,然后像

set DrawMode = OwnerDrawFixed; and hook the DrawItem event, then something like

    private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
    {
        if (e.Index == -1)
            return;
        ComboBox combo = ((ComboBox) sender);
        using (SolidBrush brush = new SolidBrush(e.ForeColor))
        {
            e.DrawBackground();
            e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, brush, e.Bounds, new StringFormat(StringFormatFlags.DirectionRightToLeft));
            e.DrawFocusRectangle();
        }
    }

这篇关于C#中的右对齐组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆