0

現在、動的に作成された長方形オブジェクトにイベントハンドラーを割り当てようとしています。これらのオブジェクトは、配列内のデータに基づいてループで作成されます。

for(int a = 0;  a < array.getlength(0); a++)
{
   //draw rectangle on each iteration
   rectangle shape = new rectangle();

   shape.width(200);
   shape.height(50);

   shape.posTop(posx);
   shape.posLeft(posy);

   posx = posx + 20;
   posy = posy + 50;

   //code to draw onto Canvas object etc...
}

このオブジェクトの各反復にマウスクリックイベントを割り当てて、それぞれに関する情報を取得できるようにする方法はありますか?

4

1 に答える 1

-1

このようなもので試してみましたか

for(int a = 0;  a < array.getlength(0); a++)
{
   //draw rectangle on each iteration
   rectangle shape = new rectangle();

   shape.width(200);
   shape.height(50);

   shape.posTop(posx);
   shape.posLeft(posy);

   posx = posx + 20;
   posy = posy + 50;

   shape.click.MouseDown += new MouseButtonEventHandler(shape_MouseDown);

   //code to draw onto Canvas object etc...
}

私が覚えているとき、正しい図形にはクリックイベントはありませんが、mousedownのような他のマウスイベントがあります。

于 2012-06-26T12:10:42.843 に答える