c# - 如何翻转字符串?

标签 c# winforms

我如何在 c# 应用程序中翻转字符串,例如:“AMBULANCE”文本被视为镜像。我不知道从哪里开始使用 .im 使用 c# 表单应用程序

我试过反转字符串,但是否有可能翻转字符串(如镜像)?

喜欢:ƎƆИA⅃UᙠMA

这不是在 SO post 中反转

最佳答案

除了 Sergey 概述的方法外,您还可以使用 Graphics.ScaleTransform()反射(reflect)关于 Y 轴的一切。

例如,创建一个默认的 Windows 窗体应用程序并将以下 OnPaint() 放入其中,然后运行它:

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    string text = "This will come out backwards";

    e.Graphics.ScaleTransform(-1, 1);
    float w = e.Graphics.MeasureString(text, this.Font).Width;
    e.Graphics.DrawString(text, this.Font, Brushes.Black, -w, 0);
}

输出:

The text reflected about Y

您也可以使用 Graphics.RotateTransform() 来旋转文本,并使用 Graphics.ScaleTransform(1, -1) 将其反转为以及镜像它:

enter image description here

关于c# - 如何翻转字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30568360/

相关文章:

c# - Duplicate Key 错误,但在使用调试点运行时不会重新创建

c# - 通用 ToSelectListItem 方法

c# - UserControl引发异常“跨线程操作无效”

c# - 在“保存文件”提示中使用适当的扩展名保存文件

c# - 如何将位图转换为图像

java - 在 Java 中通过 Bouncy CaSTLe 验证 pkcs7 SignedData

c# - 在 ViewState 中存储数据表

c# - MongoDB c# 驱动程序使用 upsert 和 updateMany

c# - 仅在面板中水平滚动

c# - WinForm 多线程。是否使用 backgroundWorker?