Link to home
Start Free TrialLog in
Avatar of rsammut
rsammut

asked on

C# Panel Graphics disappear

Hi,

 I am new to the Panel in the VS.Net Environment.  I am using a Panel to draw a Map as follows (the map is made up of Lightblue points):

.
.
Graphics g = panel1.CreateGraphics();
//Looping through an ArrayList of WayPoints (an object I created)
foreach(WayPoint wp in arrListWayPoints)
{
   g.DrawEllipse(new Pen(Color.LightBlue),wp.x,wp.y,2,2);
}
.
.

Then I added a scrollbar to view the points outside of the boundaries of the panel. I had to add a label to the panel (outside the viewable area) so that it will scroll to that point as follows:

.
.
Label l = new Label();
l.Text = "";
l.Location = new System.Drawing.Point(784, 448); //784,448 is a point outside of the viewable area
panel1.Controls.Add(l);
panel1.AutoScroll = true;
.
.

Now the Problem is that when I move the scrollbars to view an area of the panel, the graphics disappear. I tried using the panel1.Refresh property but it did not help.  

any help is welcomed,
Mr. R. Sammut.
Avatar of SimesA
SimesA

Where do you draw the map? It needs to be in the Paint event handler.
A better solution would be to draw your map to an off-screen bitmap, then draw that to the panel in the Paint event. (Taking care to offset the image to reflect the position of the scroll bars.)

The map need only be drawn once, and it would prevent any flicker as the image was redrawn to the screen.
Avatar of rsammut

ASKER

Hi, Simes

No I'm not drawing the map in the paint event handler.  I need to draw the map when the user asks to and not every time the paint event is called.

Do you know of a good tutorial which explains how to save the panel to bitmap and loading it to the paint event?

thanks
Avatar of rsammut

ASKER

Hi, Simes

No I'm not drawing the map in the paint event handler.  I need to draw the map when the user asks to and not every time the paint event is called.

Do you know of a good tutorial which explains how to save the panel to bitmap and loading it to the paint event?

thanks
ASKER CERTIFIED SOLUTION
Avatar of SimesA
SimesA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rsammut

ASKER

That worked great!!


thanks a lot,
Mr. R . Sammut