Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.23 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. OnPaint doesn't draw correctly
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace Junk
  12. {
  13. public partial class Form1 : Form
  14. {
  15.     public Form1()
  16.     {
  17.         InitializeComponent();
  18.     }
  19.  
  20.     protected override void OnPaint(PaintEventArgs eventArgs)
  21.     {
  22.         using (Font myFont = new System.Drawing.Font("Helvetica", 40,  FontStyle.Italic))
  23.             {
  24.             eventArgs.Graphics.TranslateTransform(0, 0);
  25.             Point p;
  26.             eventArgs.Graphics.DrawString("Hello C#", myFont, System.Drawing.Brushes.Red, 200, 200);
  27.             } //myFont is automatically disposed here, even if an exception was thrown            
  28.     }
  29. }
  30. }
  31.        
  32. protected override void OnPaint(PaintEventArgs eventArgs)
  33. {
  34.     using (Font myFont = new System.Drawing.Font("Helvetica", 40,  FontStyle.Italic))
  35.         {
  36.         eventArgs.Graphics.TranslateTransform(0, 0);
  37.         Point p = this.PointToScreen(new Point(200, 200));
  38.         eventArgs.Graphics.DrawString("Hello C#", myFont, System.Drawing.Brushes.Red, p);
  39.         } //myFont is automatically disposed here, even if an exception was thrown            
  40. }