C# 在C语言中如何将按钮的值传递给程序#

C# 在C语言中如何将按钮的值传递给程序#,c#,C#,我想将按钮的文本值传递给C#中的一个过程,请帮助我至少可以说,您的问题很模糊,因此我将假设一些事情可能是错误的 假设这是Winforms,您所说的过程是指方法或函数,并且您已经成功地将名为button1的按钮放置到表单上,那么您首先会将事件处理程序附加到按钮上的Click事件。您可以通过设计器或代码执行此操作 // The button1_Click is a method which we'll define in a moment button1.Click += new EventHand

我想将按钮的文本值传递给C#中的一个过程,请帮助我

至少可以说,您的问题很模糊,因此我将假设一些事情可能是错误的

假设这是Winforms,您所说的过程是指方法或函数,并且您已经成功地将名为button1的按钮放置到表单上,那么您首先会将事件处理程序附加到按钮上的Click事件。您可以通过设计器或代码执行此操作

// The button1_Click is a method which we'll define in a moment
button1.Click += new EventHandler(button1_Click);
然后您将编写一个方法来接收该事件:

protected void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show(button1.Text);
}
如果您有多个按钮,并且只希望根据按钮的文本属性做出反应,则可以为所有按钮创建一个事件处理程序

protected void SomeButton1_Click(object sender, EventArgs e)
{
    // By casting the sender to a button we can get a hold 
    // of a reference to the button that caused the event. 
    // Just be careful not to hook up anything that isn't a 
    // button to the event.

    Button b = (Button)sender;

    MessageBox.Show(b.Text);
}

当你搜索c#事件处理程序时,有大量的资源。这显示在最重要的结果中,乍一看似乎涵盖了基础知识。

ASP.NET?Winforms?需要更多的信息吗?易卜拉欣。你是指存储过程还是方法?