• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

Graphics in C#

Hi,

I have a WinForms application that has a multiline text-box on a form. I want to draw some text on this text-box using the Graphics object of the textbox.

I can render a line of text ok, but when I resize the textbox by expanding the size of the form (the text-box is anchored to expand with the form), the text disappears. What is the best technique to re-render the text whenever the textbox contents are repainted?

Cheers,

Paul
0
Sterry
Asked:
Sterry
1 Solution
 
utter77Commented:
Hi.

Override the "onpaint" method and do your graphics there.

Then call base.onpaint(e);
0
 
dampseyCommented:
you may use

this.SetStyle(ControlStyles.ResizeRedraw, true);

in the contstructor of your custom control, or in an other place where apopriate.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
In the Paint() event, make sure you are using "e.Graphics" and NOT using CreateGraphics().
0
 
BIOGENIUSCommented:
Put your code in the onpaint event.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now