Drawing Lines on specific panel

G

Guest

Hi,

I've windows form, in this form i've a panel.

I want to draw lines inside the panel using the panel coordinates( meaing
that the left upper corner of the panel is 0,0), how can i do it?

Thanks,
Gidi.
 
G

Guest

Hi,

I found out that i can draw on the panel with panel1.Paint event.

my question now is, how can i draw lines in a specific location, at when the
form loads and not call the paint event again with the lines will be erased ?

Thanks,
Gidi.
 
K

Kevin Spencer

The Paint event occurs every time the Control needs to be painted, so you
just put your code in there, and it will be redrawn automatically whenever
the Panel is repainted.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
G

Guest

Thanks Kevin,

the problem is that my form heightis smaller then my panel height, so i have
to scroll the panel up and down to see all it's content. now when i scroll
the panel the paint event starts again, but not from point (0,0) of the
orginal panel but from the point that the scroll stopped and i don't want
that. I want to draw the lines one time from height = 0 to panel's height,
without calling the drawing line again after scrolling.

how can i do it?

Thanks,
Gidi.
 
I

Ido Samuelson

you can't. Drawing using the Graphics object is via GDI+. It means you will
have to redraw everything on every paint event.
If you don't, your drawing will be cleared when another window will hover
your panel and you will lost your drawing.

For performance you can use double buffering and pre initialization of some
of the objects.
 
P

Peter Duniho

Gidi said:
Thanks Kevin,

the problem is that my form heightis smaller then my panel height, so i have
to scroll the panel up and down to see all it's content. now when i scroll
the panel the paint event starts again, but not from point (0,0) of the
orginal panel but from the point that the scroll stopped and i don't want
that. I want to draw the lines one time from height = 0 to panel's height,
without calling the drawing line again after scrolling.

how can i do it?

As has been mentioned, in the Windows display paradigm requires that you
always respond to the Paint event, drawing your image each time.

You can cache your drawing to a bitmap if you want persistence without
having to go through all of the drawing code each time, but a) this is
often not actually required in order to achieve good performance, and b)
it won't address what appears to be your _actual_ question.

Specifically, it sounds as though you are having trouble with the
scrolling aspect of the drawing. You need to handle this yourself,
regardless of how you actually do the drawing. The basic issue is that
the drawing origin of the control doesn't actually change according to
the scrollbar position.

You can address this either by using the Panel's AutoScrollPosition
property to offset your own drawing (either explicitly or by changing
the Transform property of the Graphics object you're using for drawing),
or you can just "nest" your custom-drawn Panel inside a different Panel
or UserControl that handles the actual scrolling (in that way, you'll
always be drawing relative to your custom-drawn Panel's origin, and that
Panel will be moved as appropriate within the control that's actually
scrolling.

Pete
 

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