locked
textbox RRS feed

  • Question

  • Hi All

    I want to display a number in text box (like calculator) on the click of a button. i am able to handle the click event using a function but not able to display the value. i used textbox.text but all in vain. please Help

    Thanx in advance

    Tuesday, November 23, 2010 10:42 AM

Answers

  • Have you tried something like this:

    textBox1.Text += button1.Text;


    GandRalph the Red
    • Proposed as answer by Prashant Khandelwal Tuesday, November 23, 2010 11:02 AM
    • Marked as answer by Jing0 Monday, November 29, 2010 8:18 AM
    Tuesday, November 23, 2010 10:55 AM
  • You mean you want to sum the number on a button click? Like, your button has number 2, when pressing it for the 1st time, the textBox gets number 2. When pressing it for the 2nd time, textBox gets number 4, or again 2?

    1st case: GandRalph solution

    2nd case:  textBox1.Text = button1.Text;

    • Marked as answer by Jing0 Monday, November 29, 2010 8:18 AM
    Tuesday, November 23, 2010 12:57 PM
  • Assuming you have a TextBox called textBox1 in which you're building up your value and several buttons (Button1, Button2, etc.) that represent your numbers: 

    Private Sub AnyButton_Click( ByVal sender as Object, byVal e as EventArgs ) _
      Handles Button1.Click, Button2.Click, ... 
    
      Dim btn as Button = DirectCast( sender, Button ) 
    
      Me.textBox1.Text &= btn.Text
    
    End Sub
    
    


    Regards, Phill W.
    • Marked as answer by Jing0 Monday, November 29, 2010 8:18 AM
    Tuesday, November 23, 2010 1:00 PM

All replies

  • Have you tried something like this:

    textBox1.Text += button1.Text;


    GandRalph the Red
    • Proposed as answer by Prashant Khandelwal Tuesday, November 23, 2010 11:02 AM
    • Marked as answer by Jing0 Monday, November 29, 2010 8:18 AM
    Tuesday, November 23, 2010 10:55 AM
  • You mean you want to sum the number on a button click? Like, your button has number 2, when pressing it for the 1st time, the textBox gets number 2. When pressing it for the 2nd time, textBox gets number 4, or again 2?

    1st case: GandRalph solution

    2nd case:  textBox1.Text = button1.Text;

    • Marked as answer by Jing0 Monday, November 29, 2010 8:18 AM
    Tuesday, November 23, 2010 12:57 PM
  • Assuming you have a TextBox called textBox1 in which you're building up your value and several buttons (Button1, Button2, etc.) that represent your numbers: 

    Private Sub AnyButton_Click( ByVal sender as Object, byVal e as EventArgs ) _
      Handles Button1.Click, Button2.Click, ... 
    
      Dim btn as Button = DirectCast( sender, Button ) 
    
      Me.textBox1.Text &= btn.Text
    
    End Sub
    
    


    Regards, Phill W.
    • Marked as answer by Jing0 Monday, November 29, 2010 8:18 AM
    Tuesday, November 23, 2010 1:00 PM