加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在DataGridViewCell中设置字符串的方向?

发布时间:2020-12-16 01:41:21 所属栏目:百科 来源:网络整理
导读:如何在DataGridViewColumn中为特定DataGridViewCell设置RightToLeft属性? 解决方法 我知道这是一个老问题,但正如其他人所说,DataGridViewCell和DataGridViewColumn没有RightToLeft属性.但是,这个问题有变通方法: 处理 CellPainting 事件并使用 TextFormatF
如何在DataGridViewColumn中为特定DataGridViewCell设置RightToLeft属性?

解决方法

我知道这是一个老问题,但正如其他人所说,DataGridViewCell和DataGridViewColumn没有RightToLeft属性.但是,这个问题有变通方法:

>处理CellPainting事件并使用TextFormatFlags.RightToLeft标志:

private void RTLColumnsDGV_CellPainting(object sender,DataGridViewCellPaintingEventArgs e)
   {
      if (e.ColumnIndex == RTLColumnID && 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;
       }
   }

(代码来自CodeProject question.)
>如果它只是DGV中的一个特定单元格,您可以尝试在单元格内容的开头插入不可见的RTL character(U 200F).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读