Results 1 to 2 of 2

Thread: Issue with the TextRenderer when drawing text when Graphics.Save() is called

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Issue with the TextRenderer when drawing text when Graphics.Save() is called

    Hi,
    I am having an issue when calling Graphics.Save where it seems to double the transformation of the TextRenderer (when it comes to placement - I haven't checked it with other things)!

    The below works fine and "Hello World!" is rendered in the top left of the box...
    When you uncomment the "Dim state = e.Graphics.Save()" line it then seems to gets transformed in relation to the same transformation that it already had applied!

    VB.Net Code:
    1. Dim Control = DirectCast(sender, Control)
    2.  
    3. Dim Bounds = Control.ClientRectangle
    4.  
    5. Dim t As New System.Drawing.Drawing2D.Matrix
    6. t.Translate(32, 32)
    7. e.Graphics.Transform = t
    8.  
    9. Using p As New Pen(SystemColors.Highlight, 1)
    10.     e.Graphics.DrawRectangle(p, Bounds)
    11. End Using
    12.  
    13. 'Dim state = e.Graphics.Save()
    14.  
    15. TextRenderer.DrawText(e.Graphics, "Hello World!", Control.Font, Bounds, Control.ForeColor, TextFormatFlags.PreserveGraphicsTranslateTransform

    Any sugguestions?

    Thanks in advance,
    Kris

  2. #2

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Issue with the TextRenderer when drawing text when Graphics.Save() is called

    I spoke too soon (old response below)... it appears that you cannot call .Restore again to reset everything so this counts the solution that I had thought I had found out

    OLD RESPONSE:
    I found out, if I restore the state right after I save it, that it works as expected...

    This should not be required though!

Posting Permissions

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



Click Here to Expand Forum to Full Width