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を探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・14歳の自分に衝撃の事実を告げてください
- ・架空の映画のネタバレレビュー
- ・「お昼の放送」の思い出
- ・昨日見た夢を教えて下さい
- ・ちょっと先の未来クイズ第4問
- ・【大喜利】【投稿~10/21(月)】買ったばかりの自転車を分解してひと言
- ・メモのコツを教えてください!
- ・CDの保有枚数を教えてください
- ・ホテルを選ぶとき、これだけは譲れない条件TOP3は?
- ・家・車以外で、人生で一番奮発した買い物
- ・人生最悪の忘れ物
- ・【コナン30周年】嘘でしょ!?と思った○○周年を教えて【ハルヒ20周年】
- ・ハマっている「お菓子」を教えて!
- ・最近、いつ泣きましたか?
- ・夏が終わったと感じる瞬間って、どんな時?
- ・10秒目をつむったら…
- ・人生のプチ美学を教えてください!!
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・都道府県穴埋めゲーム
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
パソコンキーボードで時分秒を...
-
IF関数でEmpty値を設定する方法。
-
動的配列が存在(要素が有る)か...
-
EXCEL VBA で、0から?1から?
-
For文と配列
-
VB.net 引数で配列変数を渡す際...
-
五目並べのプログラムを配列と...
-
配列の要素数を超えた参照のコ...
-
VBAで配列の計算
-
格闘ゲームのコマンド判定について
-
VBA 配列で重複した単語が格納...
-
変数を動的に作るには?
-
Excel VBAで配列の途中から(X)M...
-
VBでbyte配列型のインスタンス...
-
PowerShell にて、配列の計算を...
-
エクセル:バグという名の仕様?
-
Sourcearrayの読み方を教えてく...
-
複数のテキストボックスに同じ...
-
System.err. printlnとSystem.o...
-
ダブルクォーテーションのrepla...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
IF関数でEmpty値を設定する方法。
-
パソコンキーボードで時分秒を...
-
VBAで配列の計算
-
EXCEL VBA で、0から?1から?
-
変数を動的に作るには?
-
動的配列が存在(要素が有る)か...
-
VB.net 引数で配列変数を渡す際...
-
VBで作った乱数を一度も重複さ...
-
複数のテキストボックスに同じ...
-
VBでbyte配列型のインスタンス...
-
遅延バインディングを使用でき...
-
配列の要素数を超えた参照のコ...
-
C言語 重複しない4ケタの乱数...
-
【MFC】GetCount()とGetSize()...
-
C# での文字列パディング
-
五目並べのプログラムを配列と...
-
For文と配列
-
ジャグ配列とは
-
Excel VBAで配列の途中から(X)M...
-
10進数を4桁のバイト配列に格納...
おすすめ情報