Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#将列表框设置为RTL_C#_Listbox_Right To Left - Fatal编程技术网

c#将列表框设置为RTL

c#将列表框设置为RTL,c#,listbox,right-to-left,C#,Listbox,Right To Left,为了给列表框中的文本上色,我找到了本指南(我正在visual studio 2012上使用windows窗体应用程序)。 代码正在运行,但问题是我想以从右到左的模式使用文本框,但当我在列表框设置中更改它时,它不起作用,因此我假设需要在代码中以某种方式更改它,这就是我需要您的帮助的原因。 非常感谢你! 另外,您的y位置是0,因此每次插入消息时,它都在左侧。 要把它放在右边,你必须重新计算位置 看看下面的例子 private void listBox1_DrawItem(object sender,

为了给列表框中的文本上色,我找到了本指南(我正在visual studio 2012上使用windows窗体应用程序)。 代码正在运行,但问题是我想以从右到左的模式使用文本框,但当我在列表框设置中更改它时,它不起作用,因此我假设需要在代码中以某种方式更改它,这就是我需要您的帮助的原因。 非常感谢你!
另外,您的y位置是0,因此每次插入消息时,它都在左侧。 要把它放在右边,你必须重新计算位置

看看下面的例子

private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    MyListBoxItem item = listBox1.Items[e.Index] as MyListBoxItem; // Get the current item and cast it to MyListBoxItem
    if (item != null)
    {
        e.Graphics.DrawString( // Draw the appropriate text in the ListBox
                   item.Message, // The message linked to the item
                   listBox1.Font, // Take the font from the listbox
                   new SolidBrush(item.ItemColor), // Set the color 
                   width - 4, // X pixel coordinate
                   e.Index * listBox1.ItemHeight,
                   new StringFormat(StringFormatFlags.DirectionRightToLeft)); // Y pixel coordinate.  Multiply the index by the ItemHeight defined in the listbox.                
    }
    else
    {
        // The item isn't a MyListBoxItem, do something about it
    }
}

列表框本机为左对齐,您无法在UIR编辑器中对此进行更改。您可以在创建要传递到列表框的字符串时应用适当的对齐元素:请参阅
InsertListItem
函数的Item Label参数的联机帮助。所有转义码将应用于插入列表框的每一行;无法将默认格式样式应用于控件。

它不起作用,如果句子很长,它会在右侧显示最后两个字母,否则它不会显示任何内容来解释如何获得水平滚动条。太棒了!它工作正常,但并不完美,你能想出任何方法使列表框中的文本更清晰吗?看起来很模糊。。。编辑:如果我在属性中始终打开滚动条,它将显示但不活动。。。您不能单击itAt,因为它首先为RTL问题找到了更好的解决方案<代码>e.Graphics.SmoothingMode=SmoothingMode.AntiAlias用于模糊问题。使用滚动条查看其他问题或打开一个新问题。我没有真正理解你的答案。。。我应该怎样做才能使它成为RTL(如果可能的话)?