2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

イベントハンドラの引数object senderってなんだ?

Posted at
title.rb

private void buttons_Click(object sender, EventArgs e)
{
	if(((Button)sender).Text == correctText)
	{
		timer1.Stop();
	}

(Button)senderの役割というか意味が分からなかったので、記事にします。
このsenderはおそらくobject sendersenderを使っている??

調べたら....
「イベントの発生元のコントロールオブジェクト」が格納されているらしい

senderは同じようなボタンが複数あり、一つずつイベントハンドラーを書くのが
面倒な時に役立つ

senderを見ればクリックされたオブジェクトが取得できる
例)Button1の実体(情報??)がsenderに入ってくる

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?