Text written with TextRenderer overwritten by other Controls?

  • Thread starter Thread starter Jim S
  • Start date Start date
J

Jim S

Hi everyone.

I'm trying to write text to a Windows Form with TextRenderer.Drawtext,
and it works fine - until I select an item from the Menu
(System.Windows.Forms.MenuStrip) above it - at which point any text in
the Form area underneath where the menu drops down gets erased.

Here's the code I'm using to write to the Form - from a method within my
Form class:

Graphics g = this.CreateGraphics();
TextRenderer.DrawText(g, "Some Text", this.Font, new Point(10, 50),
SystemColors.WindowText, TextFormatFlags.Default);

If I put a Text Control on the form at design time in VS05, that Text
Control DOESN'T get overwritten.

So, text that I'm adding manually at runtime with TextRenderer appear
but gets stomped on by other Controls, while Controls (eg: TextControl)
added at design time are preserved.

Any ideas? I'm stumped and assume there's something that I need to call
in terms of Suspending Layout or Resuming or something like that, but no
idea what.

Thanks for any/all help!

- J
 
Where is this code? It should be in the OnPaint method.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.
 
Back
Top