Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复此事件args c_C#_Visual Studio_Visual Studio 2015 - Fatal编程技术网

C# 如何修复此事件args c

C# 如何修复此事件args c,c#,visual-studio,visual-studio-2015,C#,Visual Studio,Visual Studio 2015,我正在尝试建立我自己的简单计算器 我有这个方法,从0到10有10个参考 private void button_Click_1(object sender, EventArgs e) { Button b = (Button)sender; tb.Text += b.ToString(); }` 一切正常,但发送到文本框的文本附带了我不需要的额外内容 我只想显示我在计算器上点击的数字。我想隐藏System.windows.forms.button

我正在尝试建立我自己的简单计算器

我有这个方法,从0到10有10个参考

private void button_Click_1(object sender, EventArgs e)
    {
        Button b = (Button)sender;
        tb.Text += b.ToString();
    }`
一切正常,但发送到文本框的文本附带了我不需要的额外内容

我只想显示我在计算器上点击的数字。我想隐藏System.windows.forms.button,Text:并仅显示7在本例中

使用button属性而不是ToString

使用Button的属性而不是ToString


正如Adil指出的,只需使用Text属性

通过创建一个可重用的事件处理程序,而不是使用生成的事件处理程序,可以进一步改进代码库

而不是

private void button_Click_1(object sender, EventArgs e)
{
    Button b = (Button)sender;
    tb.Text += b.Text;
}
private void button_Click_2(object sender, EventArgs e)
{
    Button b = (Button)sender;
    tb.Text += b.Text;
}
private void button_Click_3(object sender, EventArgs e)
{
    ...
您可以只使用单个事件处理程序。请记住更新按钮上的指针以指向此事件处理程序

private void numericButton_Click(object sender, EventArgs e)
{
    Button b = (Button)sender;
    tb.Text += b.Text;
}`

正如Adil指出的,只需使用Text属性

通过创建一个可重用的事件处理程序,而不是使用生成的事件处理程序,可以进一步改进代码库

而不是

private void button_Click_1(object sender, EventArgs e)
{
    Button b = (Button)sender;
    tb.Text += b.Text;
}
private void button_Click_2(object sender, EventArgs e)
{
    Button b = (Button)sender;
    tb.Text += b.Text;
}
private void button_Click_3(object sender, EventArgs e)
{
    ...
您可以只使用单个事件处理程序。请记住更新按钮上的指针以指向此事件处理程序

private void numericButton_Click(object sender, EventArgs e)
{
    Button b = (Button)sender;
    tb.Text += b.Text;
}`

还指定删除拖放asp文本框时默认出现的文本:还指定删除拖放asp文本框时默认出现的文本:默认情况下,ToString通常返回调试信息类名。改为使用Text属性。默认情况下,ToString通常返回调试信息类名。改为使用文本属性。