1

このポップアップ関数を呼び出してメールを送信するボタンが 5 つあります。どのクリックされたボタンが関数を呼び出したのかを知るにはどうすればよいですか?

   public void popup(object sender, EventArgs e)
    {

        if (MessageBox.Show("You may not Bind, Change, Or Alter Insurance Coverage through e-mail. Confirmation of this e-mail by us initiates any changes to your Insurance. If you need any immediate service please contact our office at 1-800-875-5720.", "IMPORTANT!", MessageBoxButtons.OKCancel) == DialogResult.OK)
        {

            {
                string email = "mailto:davidadfa.t@ifdafdadf.com";
                Process.Start(email);
            }
        }
    }
4

5 に答える 5

5

イベント ハンドラのsenderオブジェクトは、押されたボタンになります。

Button b = sender as Button;
于 2012-04-06T13:54:17.627 に答える
2

送信者オブジェクトは、メソッドを呼び出すボタンです。

var buttonId = ((Button)sender).ID;
于 2012-04-06T13:57:22.010 に答える
1

イベントの送信者は、クリックされた Button オブジェクトです。

ただし、コードを少しリファクタリングして別のボタンクリックイベントを設定し、その機能を別のメソッドに移動してから、さまざまなクリックイベントから呼び出し、最終的にパラメータを送信する方がよいかもしれないことを知る必要がある場合

于 2012-04-06T13:54:27.013 に答える
1

試す

public void popup(object sender, EventArgs e)
{
Button TheButtonClicked = sender as Button; // this gives access to the button 

    if (MessageBox.Show("You may not Bind, Change, Or Alter Insurance Coverage through e-mail. Confirmation of this e-mail by us initiates any changes to your Insurance. If you need any immediate service please contact our office at 1-800-875-5720.", "IMPORTANT!", MessageBoxButtons.OKCancel) == DialogResult.OK)
    {

        {
            string email = "mailto:davidadfa.t@ifdafdadf.com";
            Process.Start(email);
        }
    }
}

参照については、これを参照してください。

于 2012-04-06T13:56:42.253 に答える