c# - 如何使用 Compact Framework 垂直绘制文本

标签 c# user-interface windows-mobile drawing

我需要直接在 Windows Mobile 窗体上垂直绘制文本。这是一个 Compact Framework 2.0 应用程序。我有以下测试代码在 Windows 窗体应用程序中工作,但它不适用于紧凑型框架,因为没有 DirectionVertical StringFormatFlag。有没有其他方法可以在 Windows Mobile 上做同样的事情?升级到 Compact Framework 3.5 没有帮助。它具有与 2.0 相同的 StringFormatFlags。

private void TestDrawVertically()
{
  Font myFont = new Font(FontFamily.GenericSerif, 10, FontStyle.Bold);
  System.Drawing.Brush myBrush = new SolidBrush(Color.Black);
  Rectangle myRect = new Rectangle(10, 10, 200, 200);
  StringFormat myFormat = new StringFormat();
  myFormat.LineAlignment = StringAlignment.Center;
  myFormat.Alignment = StringAlignment.Center;
  myFormat.FormatFlags = StringFormatFlags.DirectionVertical;
  Graphics myGraphic = this.CreateGraphics();

  myGraphic.DrawString("Hello", myFont, myBrush, myRect, myFormat);
}

谢谢。

最佳答案

public static Font CreateRotatedFont(string fontname, int height, int angleInDegrees, Graphics g)
{
    LogFont logf = new LogFont();
    logf.Height = -1 * height;
    logf.FaceName = fontname;
    logf.Escapement = angleInDegrees * 10;
    logf.Orientation = logf.Escapement;
    logf.CharSet = LogFontCharSet.Default;
    logf.OutPrecision = LogFontPrecision.Default;
    logf.ClipPrecision = LogFontClipPrecision.Default;
    logf.Quality = LogFontQuality.ClearType;
    logf.PitchAndFamily = LogFontPitchAndFamily.Default;
    return Font.FromLogFont(logf);
}

然后像这样使用它:

Graphics myGraphic = this.CreateGraphics();
Font myFont = CreateRotatedFont("Tahoma", 32, 90, myGraphic);
myGraphic.DrawString("Hello", myFont, myBrush, myRect, myFormat);

关于c# - 如何使用 Compact Framework 垂直绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1161114/

相关文章:

c# - 引用类型在内部是如何工作的?

安卓用户界面 : what kind of layout options are mutually exclusive?

c++ - 适用于 Windows Mobile 的 OpenGL ES 2.0 SDK

c# Matrix of pictureBox 的

sql - 如何在 Windows Mobile 6.5 中使用数据库

c# - 一个Windows服务中的多个服务进程(System.ServiceProcess.ServiceBase)

c# - string.Format 如何在尽可能多的对象中表格?

c# - const 字符串是否符合垃圾回收条件?

user-interface - 如何在Flutter中制作一个适合整个屏幕的列

ios - 可调整大小的 Collection View 单元格