gdi drawing

G

Guest

hi, this is a n00b question but when i draw on a panel in my form using GDI
and a pen, but when i minimize the form, or put anything in front of the item
in drawing on, the graphics go away. how can i fix this?
 
G

Guest

iwdu15 said:
hi, this is a n00b question but when i draw on a panel in my form using GDI
and a pen, but when i minimize the form, or put anything in front of the item
in drawing on, the graphics go away. how can i fix this?

Every time the form redraws the panel control it has to draw it from
scratch. So, in order for your lines to reappear you need to redraw
them every time the form redraws the panel. Handle the Control.Paint
event and do your drawing of lines in there.

Chris
 
G

Guest

how would i do that? like i have my lines being drawn on a mousemove event of
a panel...is there a simple way to save them without using overloaded
functions?
 
P

Peter Oliphant

I do this:
:
form->Paint += new PaintEventHandler( this,
$ThisClass::paint_Event_Handler ) ;
:
void Paint_Event_Handler( Object^, PaintEventArgs^ e)
{
Graphics^ graphics = e->Graphics ;
// use graphics to draw your primitives here, like this:
Pen^ pen = gcnew Pen(Color::Red) ;
graphics->DrawRectangle( pen, 0, 0, 20, 20 ) ; // etc.
}

Note this draws your graphics every time the 'form's Paint event occurs.
This happens whenever some portion of 'form' is covered and then uncovered.
Hence, to actually SEE the graphics drawn in this way you need to execute
form->Refresh() to put on the screen what your drawing in the Paint event (I
think Refresh() causes the Paint event to fire, or at least executes the
Paint event handler).

This was all assuming /clr syntax in 2005. If you do use 2005, then I
STRONGLY recommend setting the DoubleBuffered property of your 'form' to
true, this will eliminate any flicker you might get. I personally also
double buffer manually, but that's another topic... : )

[==P==]
 
W

wizofaus

iwdu15 said:
how would i do that? like i have my lines being drawn on a mousemove event of
a panel...is there a simple way to save them without using overloaded
functions?
--
Not sure what you mean by "overloaded functions", but yes, you would
have to save the information each time the mouse is moved, if you want
to be able to redraw it later after a screen refresh. Where and how
you save this is entirely up to you of course - a simple
std::vector<Gdiplus::point> would probably suffice (you can then pass
this direct to Gdiplus::Graphics::DrawLines).
 
G

Guest

but how would i do this if i want to draw a line according to how the user
moves the mouse? kinda like a paint program
 
A

Arnaud Debaene

iwdu15 said:
but how would i do this if i want to draw a line according to how the
user moves the mouse? kinda like a paint program

In the mouse handler, save information about the drawing "strokes" (probably
a collection of points). In OnPaint, redraw the lines between those points?

Arnaud
MVP - VC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top