-1
public class Car
{
  public string StreetName;
  public RectangleShape Car_Shape;
  public int ArrivalTime, Axis, Lane;
  public string Direction;
  public double Car_Delay;
  public bool Mobile;
  public Stopwatch Sw = new Stopwatch();
  public Car(int ArriT)
  {
      ArrivalTime = ArriT;
  }
  public void SetDelay()
  {
  }
}

This is the Code, I add every rectangular shape when creating an instance "Car" to a ShapeContainer on the main form, what I want to do is when I press on any of the shapes, data related to this shape are shown in a textbox, like "Direction", or "Delay" I tried to use delegation, I made an event but I can't pass the paramaters...

Thanks a lot

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
YMELS
  • 153
  • 1
  • 4
  • 18
  • Can you post your form code as well? You will certainly need to store the Car instances created, then find out which one was "clicked", possibly in the form's overridden OnClick() method... – Alan Mar 24 '12 at 20:30
  • please dont include the language in the title. Thats what tags are for – Sam Axe Mar 24 '12 at 22:06

2 Answers2

0

Use the visual power pack Rectangle shape class which implements events, or otherwise just make a user control for Rectangle and simply listen to the click event. to recognize which car suits the rectangle you can save a dictionary, but that would beb ugly, or you can have the car itself also be a user control which listens to the rectangle's click event and invokes it's own click event, so you can access all the car's properties via the sender parameter of the event.

SimpleVar
  • 14,044
  • 4
  • 38
  • 60
0

(sorry for my bad english)

Does your RectangleShape raise Click or MouseDownEvents? If so, you could do something like:

public class Car
{
    public string StreetName;
    public RectangleShape Car_Shape;
    public int ArrivalTime, Axis, Lane;
    public string Direction;
    public double Car_Delay;
    public bool Mobile;
    public Stopwatch Sw = new Stopwatch();

    public Action<Car> ShapeClicked;

    public Car(int ArriT, Action<Car> shapeClicked)
    {
        ArrivalTime = ArriT;
        this.ShapeClicked = shapeClicked;

        Car_Shape.Click += (sd,args) =>
        {
            if (Clicked != null)
                Clicked(this);
        };

    }
    public void SetDelay()
    {
    }
}

To use is easy:

Car car = new Car(0, OnShapeClicked);

public void OnShapeClicked(Car car)
{
    MessageBox.Show(car.Direction); 
}

or

Car car = new Car(0, (c) => 
{ 
    MessageBox.Show(c.Direction); 
});
Leo
  • 7,379
  • 6
  • 28
  • 44