Solved

Use e.graphics after paintevent

Posted on 2006-07-09
4
253 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office.Interop.Word Document - Detect Macros not working 16 36
C# TextBox 11 30
Not showing JavaScript in the list 5 35
ASP.NET 5 Templates 2 65
Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

10 Experts available now in Live!

Get 1:1 Help Now