如何将属性RightToLeft发送到DatagridviewCell?我试着设置
Alignement属性为“MiddleRight”但由于我的DatagridviewCell值为
阿拉伯语和英语它从右到左不显示为我想要的。
答案 0 :(得分:4)
我找到了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;
}
}
答案 1 :(得分: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 direction Property和DataGridViewCell.Style Property
方向:rtl;