
Untitled
By: a guest on
May 9th, 2012 | syntax:
None | size: 1.23 KB | hits: 13 | expires: Never
OnPaint doesn't draw correctly
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Junk
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs eventArgs)
{
using (Font myFont = new System.Drawing.Font("Helvetica", 40, FontStyle.Italic))
{
eventArgs.Graphics.TranslateTransform(0, 0);
Point p;
eventArgs.Graphics.DrawString("Hello C#", myFont, System.Drawing.Brushes.Red, 200, 200);
} //myFont is automatically disposed here, even if an exception was thrown
}
}
}
protected override void OnPaint(PaintEventArgs eventArgs)
{
using (Font myFont = new System.Drawing.Font("Helvetica", 40, FontStyle.Italic))
{
eventArgs.Graphics.TranslateTransform(0, 0);
Point p = this.PointToScreen(new Point(200, 200));
eventArgs.Graphics.DrawString("Hello C#", myFont, System.Drawing.Brushes.Red, p);
} //myFont is automatically disposed here, even if an exception was thrown
}