views:

306

answers:

1

I need to draw text VERTICALLY directly on to a Windows Mobile Form. This is a Compact Framework 2.0 application. I have the following test code working in a windows form application, but it does not work with the compact framework because there is NOT a DirectionVertical StringFormatFlag. Is there another way to do the same thing on Windows Mobile? Upgrading to Compact Framework 3.5 did NOT help. It has the same StringFormatFlags as 2.0.

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);
}

Thanks.

+3  A: 
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);
}

Then use it like this:

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