在C#中右对齐组合框 [英] Right justified combobox in C#
本文介绍了在C#中右对齐组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在默认情况下在C#ComboBox中的项目是左对齐。 是否有任何可供选择,从覆盖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?
干杯
推荐答案
您可以只设置控件样式从右至左= 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
事件,
然后像
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屋!
查看全文