Drawing on a panel?

Posted on 2004-11-18
Last Modified: 2010-04-24
I am using Managed extensions for C++ in .NET. My program must draw some rectangles on a panel, that is in the main form. I am using "Graphics g=panel->CreateGraphics();" and then use this "g" in order to draw some stuff. How do I manage to erase all the painted stuff? Changing the background color of the panel is not a solution.
Question by:Zdravko_Monov
    LVL 6

    Expert Comment

    Try panel->Refresh();
    Works for me...most of the time ;)


    Author Comment

    Ok, this really works. But how do I save the image, after resizing, or minimizing the window? It seems to me, that everything is cleared after an opation such as opening a large menu, that hides most of the panel. I want to repaint the region, that was hidden, but how?
    LVL 6

    Accepted Solution

    You can handle the Paint() event and do your drawing there.

          private: System::Void panel_Paint(System::Object *  sender, System::Windows::Forms::PaintEventArgs *  e)
                             System::Drawing::Pen* p = new System::Drawing::Pen(System::Drawing::Color::Coral);

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    734 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

    21 Experts available now in Live!

    Get 1:1 Help Now