在文本框中输入按钮的文本 [英] Input a button's text into a text box

查看:21
本文介绍了在文本框中输入按钮的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继我的上一个问题按钮由用户重命名之后,得到了快速的回答并提供了很多帮助.

Following on from my last Question Buttons to be renamed by the user which was answered quickly and helped a lot.

目前我得到了这个代码,我需要在 100 个按钮上拥有它.

At the moment I have got this code, which I need to have on 100's of buttons.

我需要知道的是如何使用按钮中的文本将它们放入需要它们的不同文本框中.

What I need to know is how to use the text from the button to put into the different text boxes that requires them.

    If Label4.Text = "Admin" Then
        With DirectCast(sender, Button)
            .Text = InputBox("Button Name", "Button Name", .Text)
        End With
    Else
        Me.TransactionBindingSource.AddNew()

        Product_NameTextBox.Text = >>>>>>Button name<<<<<<<<
        Try
            Me.ProductTableAdapter.FillByProductName(Me.Database1DataSet.Product, Product_NameTextBox.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

        ProductTextBox.Text = >>>>>>>Button2.Text<<<<<<<<
        GroupTextBox.Text = GroupTextBox1.Text
        AmountTextBox.Text = AmountTextBox1.Text
        PriceTextBox.Text = PriceTextBox1.Text
        TimeTextBox.Text = TimeOfDay
        DateTextBox.Text = DateString

        Me.Validate()
        Me.TransactionBindingSource.EndEdit()
        Me.TransactionTableAdapter.Update(Me.Database1DataSet)

        Timer2.Enabled = True
        TransNameLB.Items.Add(>>>>>>>Button2.Text<<<<<<<<)
        TransPriceLB.Items.Add(PriceTextBox.Text)

        Dim sum As Double
        For x As Integer = 0 To TransPriceLB.Items.Count - 1
            sum += Val(TransPriceLB.Items.Item(x).ToString)
        Next
        TextBox1.Text = sum.ToString

        QTYDrinksTB.Text = TransNameLB.Items.Count
    End If

End Sub

除了 >>><<<,在这里我需要获取被点击的按钮并将按钮中的文本返回到文本框/列表框中.

Everything works apart from the bits between >>> <<<, where I need to get the button that is clicked and return the text from the button into the text boxes/list box.

我有 100 个需要此代码的按钮.

I have 100's of buttons that need this code.

推荐答案

你使用上一个问题中的 With DirectCast(sender, Button),它也可以用来帮助你的其他部分.例如:

You use With DirectCast(sender, Button) from your previous question, which can also be used to help with your other parts. For example:

If Label4.Text = "Admin" Then
    With DirectCast(sender, Button)
        .Text = InputBox("Button Name", "Button Name", .Text)
    End With

Else
    Me.TransactionBindingSource.AddNew()

    With DirectCast(sender, Button)

    Product_NameTextBox.Text = .Text

    Try
        Me.ProductTableAdapter.FillByProductName(Me.Database1DataSet.Product, Product_NameTextBox.Text)
    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try

    ProductTextBox.Text = .Text
    GroupTextBox.Text = GroupTextBox1.Text
    AmountTextBox.Text = AmountTextBox1.Text
    PriceTextBox.Text = PriceTextBox1.Text
    TimeTextBox.Text = TimeOfDay
    DateTextBox.Text = DateString

    Me.Validate()
    Me.TransactionBindingSource.EndEdit()
    Me.TransactionTableAdapter.Update(Me.Database1DataSet)

    Timer2.Enabled = True
    TransNameLB.Items.Add(.Text)
    TransPriceLB.Items.Add(PriceTextBox.Text)

    End With

    Dim sum As Double
    For x As Integer = 0 To TransPriceLB.Items.Count - 1
        sum += Val(TransPriceLB.Items.Item(x).ToString)
    Next
    TextBox1.Text = sum.ToString

    QTYDrinksTB.Text = TransNameLB.Items.Count
End If

这篇关于在文本框中输入按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆