Graphics coordinates problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Graphics coordinates problem

  1. #1
    Join Date
    Jan 2012
    Posts
    1

    Question Graphics coordinates problem

    VS 2008

    On startup of this sample Windows forms application, the paint override uses DrawString to put a message on the screen. So far, so good. The problem is that there are three paint events on startup, and the 2nd or 3rd one causes the string to be drawn at a different location than where it is supposed to be.

    I first noticed this problem in a more complicated application that I'm developing and created this simple example to eliminate any other code as the source of the problem. The problem also occurs with DrawRectangle, DrawLine, and DrawEllipse.

    The 2nd and 3rd paint events occur 3 to 4 seconds after program startup. After that, the screen is redrawn correctly for the rest of program execution.

    Is this possibly a bug in C# or am I missing something obvious? Here's the code. Thanks in advance.

    #
    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.DrawString("Hello C#", myFont, System.Drawing.Brushes.Red, 200, 200);
    } //myFont is automatically disposed here, even if an exception was thrown
    }

    }
    }
    #

  2. #2
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Graphics coordinates problem

    Using your exact code compiled with Visual Studio 2010SP1/W7-Enterprise. The Paint Event was only called once in my case?
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center