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

Drawing on a panel?

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.
0
Zdravko_Monov
Asked:
Zdravko_Monov
  • 2
1 Solution
 
Svetlin_PanayotovCommented:
Try panel->Refresh();
Works for me...most of the time ;)

Svetlin
0
 
Zdravko_MonovAuthor Commented:
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?
0
 
Svetlin_PanayotovCommented:
You can handle the Paint() event and do your drawing there.
e.g.

      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);
                         e->Graphics->DrawRectangle(p,10,15,40,40);
                   }
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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