6

如何将属性 RightToLeft 插入 DatagridviewCell?我试图设置

Alignement 属性为“MiddleRight”,但由于我的 DatagridviewCell 值为

阿拉伯语和英语它没有像我想要的那样从右到左显示。

4

2 回答 2

6

我找到了一个带有 Cell_Painting 事件的解决方案,它可以工作。这是代码:

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {
        if (e.ColumnIndex == 2 && e.RowIndex >= 0)
        {
            e.PaintBackground(e.CellBounds, true);
            TextRenderer.DrawText(e.Graphics, e.FormattedValue.ToString(), e.CellStyle.Font, e.CellBounds, e.CellStyle.ForeColor, TextFormatFlags.RightToLeft | TextFormatFlags.Right);
            e.Handled = true;
        }
    }
于 2015-03-10T09:28:57.700 回答
0

要正确使用 RightToLeft 语言,您应该设置 CSS 样式 rtl。例如:

private void CustomizeCellsInThirdColumn()
{
    int thirdColumn = 2;
    DataGridViewColumn column =
        dataGridView.Columns[thirdColumn];
    DataGridViewCell cell = new DataGridViewTextBoxCell();

    cell.Style.Direction = "rtl";
    column.CellTemplate = cell;
}

有关更多信息,请阅读CSS 方向属性DataGridViewCell.Style 属性

方向:rtl;

于 2015-03-10T09:14:32.600 回答