Sunday, November 30, 2008

Targeting WVGA Screens on Windows Mobile/Smartphone

I wrote a post recently here. I showed a simple technique for supporting multiple screen resolutions when writing GDI code on Windows Mobile. The code doesn't change even with the new WVGA screens (640x800) coming to market. I've copied the code here:
private int DESIGNPOINTSPERINCH = 96;

protected override void OnPaint(PaintEventArgs e)
{
Graphics grfx = e.Graphics;
Brush foreColorBrush = new SolidBrush(Color.Black);
Font boldFont = new Font(Font.Name, 20, FontStyle.Bold);
grfx.DrawString("Hello World!",
boldFont, foreColorBrush,
20 * grfx.DpiY / DESIGNPOINTSPERINCH,
20 * grfx.DpiY / DESIGNPOINTSPERINCH);
boldFont.Dispose();
foreColorBrush.Dispose();
}

No comments: