Solved

Use e.graphics after paintevent

Posted on 2006-07-09
4
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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