Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drawing Lines on specific panel

168 views
Skip to first unread message

Gidi

unread,
Sep 26, 2007, 6:34:03 AM9/26/07
to
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.

Gidi

unread,
Sep 26, 2007, 8:18:04 AM9/26/07
to
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.

Kevin Spencer

unread,
Sep 26, 2007, 9:08:53 AM9/26/07
to
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

"Gidi" <shn...@hotmail.com.dontspam> wrote in message
news:D5E77969-CA8A-4EA1...@microsoft.com...

Gidi

unread,
Sep 26, 2007, 10:48:01 AM9/26/07
to
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.

Ido Samuelson

unread,
Sep 26, 2007, 11:37:54 AM9/26/07
to
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.

"Gidi" <shn...@hotmail.com.dontspam> wrote in message

news:1CF70135-0276-46C1...@microsoft.com...

Peter Duniho

unread,
Sep 26, 2007, 12:58:29 PM9/26/07
to
Gidi wrote:
> 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

0 new messages