Telerik,使用DropDownList样式启用RadDropDownList的文本中心?

时间:2014-08-31 15:29:58

标签: c# .net vb.net winforms telerik

我正在尝试将控件中显示的文本居中(不在菜单中),但当DropDownStyle属性设置为{{1}时,我无法找到执行此操作的方法模式。

enter image description here

似乎UI元素DropDownList仅影响RadTextBoxItem\TextAllign属性设置为DropDownStyle模式的时间:

enter image description here

我如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

我相信你引用的UI元素(主要是)用于调整下拉项目。

在项目上使用TextAlignment属性。在表单设计器中,选择Edit Items。使用DescriptionTextListDataItems添加商品,然后设置文字和TextAlignment属性。如果添加RadListDataItems,它将起作用,但下拉列表部分也将居中。

enter image description here

可能(应该)设置默认设置或者一个设置默认设置 - 我无法想象每个人都希望每个人都有所不同 - 例如通过UI Elements hive你正在调整,但那些似乎没有流过或映射到文字部分。

在代码中,如果您只是将字符串添加到items集合,它将使用默认值,因此添加Description....个对象:

Dim mi As New DescriptionTextListDataItem
mi.Text = "Over-engineered"
mi.TextAlignment = ContentAlignment.MiddleCenter

RadDropDownList1.Items.Add(mi)

请务必使用Text而不是DescriptionText,否则该项目将被停用。

enter image description here

enter image description here

答案 1 :(得分:0)

解决方案:

Private Sub RadDropDownList1_SelectedIndexChanged(sender As Object, e As Data.PositionChangedEventArgs) _
Handles RadDropDownList1.SelectedIndexChanged

    sender.DropDownListElement.
           EditableElement.
           TextAlignment = ContentAlignment.MiddleCenter

End Sub

通过这种方式,我可以使用中左对齐设置列表项,并将所选项目文本显示为居中:)

PS:是的,我需要在每次selectinex发生变化时设置allignment。