Solved

Use e.graphics after paintevent

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web Form VB.Net  import CSV 4 38
Video Player 11 23
SqlDataBase 7 48
C# Object Reference is Required for the non-static field, method, or property 10 34
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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

770 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