【问题标题】:How to draw a right-aligned string which does not fit completely in surrounding rectangle如何绘制不完全适合周围矩形的右对齐字符串
【发布时间】:2020-04-03 01:56:49
【问题描述】:
 Rectangle Location =  new Rectangle(X , Y, W, H);
 var TextFormat = new StringFormat() { Alignment = StringAlignment.Far };
 string Text = "RRRR1234567890123456789012345678901234567890RRRR";
 e.Cache.DrawString(Tekst,_Font,_Brush, Location, TextFormat);

嗨,

我正在使用此代码在矩形“位置”内右对齐字符串“文本”。如果宽度'W'大于字符串的宽度,它工作正常

iTextWidth = (int)(e.Graphics.MeasureString(Text, _Font).Width);

但如果宽度'W'小于iTextWidth,它仍然显示例如 RRRR1234567890123 代替 8901234567890RRRR

我做错了什么

【问题讨论】:

    标签: c# alignment drawstring


    【解决方案1】:

    找到了!

    Bar = "RRRR1234567890123456789012345678901234567890RRRR";
    TextFormatFlags flags =     TextFormatFlags.RightToLeft | TextFormatFlags.Right;
    TextRenderer.DrawText(e.Graphics, Bar, _Font, Location, Color.Black, flags);
    e.Graphics.DrawRectangle(Pens.Transparent, Location);
    

    【讨论】:

      猜你喜欢
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多