
No.1ベストアンサー
- 回答日時:
こんにちは。
ピクチャボックスを作成する際にクリックイベントを登録した後、クリックイベントのsenderで判断すれば良いのでは。
雑ではありますが、以下参考程度に。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private PictureBox[] pictures = new PictureBox[0];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int n = 0; n < 16; ++n)
{
Array.Resize(ref this.pictures, n + 1);
this.pictures[n] = new System.Windows.Forms.PictureBox();
this.pictures[n].Location = new System.Drawing.Point((n % 4) * 32, (n / 4) * 32);
this.pictures[n].Name = "pictureBox" + n.ToString();
this.pictures[n].Size = new System.Drawing.Size(32, 32);
this.pictures[n].TabIndex = n;
this.pictures[n].TabStop = true;
this.pictures[n].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
//↓コレがないとだめ
this.pictures[n].Click += new System.EventHandler(this.pictureBox_Click);
this.Controls.Add(this.pictures[n]);
this.pictures[n].Show();
}
}
private void pictureBox_Click(object sender, EventArgs e)
{
//senderはクリックされたピクチャボックスのどれか
PictureBox pict = sender as PictureBox;
MessageBox.Show(pict.Name);
}
}
}
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
IF関数でEmpty値を設定する方法。
-
動的配列が存在(要素が有る)か...
-
VBAで配列の計算
-
For文と配列
-
ジャグ配列とは
-
VB.net 引数で配列変数を渡す際...
-
VBでbyte配列型のインスタンス...
-
パソコンキーボードで時分秒を...
-
遅延バインディングを使用でき...
-
EXCEL VBA で、0から?1から?
-
変数を動的に作るには?
-
C言語のポインターに関する警告
-
ORA-01858: 数値を指定する箇所...
-
ループ処理の際、最後だけ","を...
-
System.err. printlnとSystem.o...
-
System.exit()の値を取得したい
-
カタカナの小文字を大文字に変...
-
javaで質問です。 文字列2023/2...
-
1~100までの数字を表示したい
-
【C#】ハッシュテーブル(連想...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
IF関数でEmpty値を設定する方法。
-
パソコンキーボードで時分秒を...
-
動的配列が存在(要素が有る)か...
-
VBAで配列の計算
-
VB.net 引数で配列変数を渡す際...
-
C言語 重複しない4ケタの乱数...
-
EXCEL VBA で、0から?1から?
-
変数を動的に作るには?
-
複数のテキストボックスに同じ...
-
配列の要素数を超えた参照のコ...
-
VBでbyte配列型のインスタンス...
-
10進数を4桁のバイト配列に格納...
-
ジャグ配列とは
-
ログデータを表示するグラフに...
-
ゲーム箱入り娘のつくりかた
-
遅延バインディングを使用でき...
-
VBで作った乱数を一度も重複さ...
-
C#の質問
-
このプログラムがわかりません
-
【MFC】GetCount()とGetSize()...
おすすめ情報