Link to home
Start Free TrialLog in
Avatar of annihil8
annihil8

asked on

Use e.graphics after paintevent

Hi,

I'm developping a program which shows gpscoordinates on a panel.
This code works fine, it shows a circle on the panel on the wright coodinates:

private void pnl_drawing_Paint(object sender, PaintEventArgs e)

{

Device _dev = new Device();

_dev.D_Id = 1;

Coordinate[] _coordinates = _dev.getCoordinates();

e.Graphics.FillEllipse(new SolidBrush(ColorArray[0]), _coordinates[0].C_X, _coordinates[0].C_Y, 10, 10);

}

When I use this code, it doesn't show the circle anymore:

private void Frm_main_Load(object sender, EventArgs e)

{

   InitializeDatabase();

   InitializeDevices();


}

private void InitializeDevices()

{

   Device _dev = new Device();

   _dev.D_Id = 1;

   Coordinate[] _coordinates = _dev.getCoordinates();

   Graphics e = pnl_drawing.CreateGraphics();

   e.FillEllipse(new SolidBrush(ColorArray[0]), _coordinates[0].C_X, _coordinates[0].C_Y, 10, 10);

}

I need the second way of coding to work because I need to repaint the dots manually. So eventually I can "Play" the route in a Timerevent.

Does anybody has an idea to solve my problem?

Grtz

Annihil8

Avatar of AlexFM
AlexFM

Device _dev;        // class member

private void pnl_drawing_Paint(object sender, PaintEventArgs e)
{
  if ( _dev != null )
  {
      Coordinate[] _coordinates = _dev.getCoordinates();
      e.Graphics.FillEllipse(new SolidBrush(ColorArray[0]), _coordinates[0].C_X, _coordinates[0].C_Y, 10, 10);
  }
}

private void Frm_main_Load(object sender, EventArgs e)
{
   InitializeDatabase();
   InitializeDevices();
}

private void InitializeDevices()
{
   _dev = new Device();
   _dev.D_Id = 1;
}
Avatar of annihil8

ASKER

Allright, and what do I need to do to "play" the coordinates?
I mean the [0] is now hardcoded but i has to be an value of the timer(1000ms/tick) Can I call the pnl_drawing_paint(..) in this timer_click event?
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

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
Nice :) It worked. Tnx!

2 remarks:
- ColorArray[index]) should stay ColorArray[0] ==> Every device has it own trackingcolor and not every second.
- Invalidate() should be Invalidate(true); or  pnl_drawing.Invalidate(); ==> Invalidate() only redraws the parentcontainer("this") and not the pnl containing the coordintates.

Grtz
Annihil8