Graphics in C#

Posted on 2010-01-08
Last Modified: 2012-05-08

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?


Question by:Sterry
    LVL 4

    Expert Comment


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

    Then call base.onpaint(e);
    LVL 8

    Accepted Solution

    you may use

    this.SetStyle(ControlStyles.ResizeRedraw, true);

    in the contstructor of your custom control, or in an other place where apopriate.
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    In the Paint() event, make sure you are using "e.Graphics" and NOT using CreateGraphics().
    LVL 4

    Expert Comment

    Put your code in the onpaint event.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now