Solved

Use e.graphics after paintevent

Posted on 2006-07-09
4
252 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:annihil8
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17067381
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;
}
0
 

Author Comment

by:annihil8
ID: 17067396
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?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 100 total points
ID: 17067422
In the timer event change some class member and invalidate form. Invalidate is indirect call to paint event handler:

Device _dev;        // class member
int index;

private void pnl_drawing_Paint(object sender, PaintEventArgs e)
{
  if ( _dev != null )
  {
      Coordinate[] _coordinates = _dev.getCoordinates();
      e.Graphics.FillEllipse(new SolidBrush(ColorArray[index]), _coordinates[index].C_X, _coordinates[index].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;
}

private void timer1_Tick(object sender, EventArgs e)
{
    index++;
    Invalidate();
}
0
 

Author Comment

by:annihil8
ID: 17067486
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

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now