Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Need help with Backspace button!!

Need help with Backspace button!!

Scheduled Pinned Locked Moved C#
tutorialquestionhelp
5 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lim Yuxuan
    wrote on last edited by
    #1

    Hi ! I am designing a simple calculator application and I am having trouble coding the backspace button. I store the data that the user had input in a string by the name of strInput with initial value strInput = "" . I display the value that the user had clicked by coding : lblDisplayPanel.Text+="value of button"; For example, lets take a look at my button 1 private void btn1_Click(object sender, EventArgs e) { lblDisplayPanel.Text += "1"; } so when I click button 1 thrice, the display panel will show "111". However, I only know how to add values to the display panel label. I tried -= but it wont work . The backspace button is supposed to remove the last value entered by the user but how do I do that ?

    W M 2 Replies Last reply
    0
    • L Lim Yuxuan

      Hi ! I am designing a simple calculator application and I am having trouble coding the backspace button. I store the data that the user had input in a string by the name of strInput with initial value strInput = "" . I display the value that the user had clicked by coding : lblDisplayPanel.Text+="value of button"; For example, lets take a look at my button 1 private void btn1_Click(object sender, EventArgs e) { lblDisplayPanel.Text += "1"; } so when I click button 1 thrice, the display panel will show "111". However, I only know how to add values to the display panel label. I tried -= but it wont work . The backspace button is supposed to remove the last value entered by the user but how do I do that ?

      W Offline
      W Offline
      Willem Ten Broek
      wrote on last edited by
      #2

      Try the following in your back space button click event

      private void btnBS_Click(object sender, EventArgs e)
      {
      lblDisplayPanel.Text = lblDisplayPanel.Text.Remove(lblDisplayPanel.Text.Lemgth - 1);
      }

      L 1 Reply Last reply
      0
      • L Lim Yuxuan

        Hi ! I am designing a simple calculator application and I am having trouble coding the backspace button. I store the data that the user had input in a string by the name of strInput with initial value strInput = "" . I display the value that the user had clicked by coding : lblDisplayPanel.Text+="value of button"; For example, lets take a look at my button 1 private void btn1_Click(object sender, EventArgs e) { lblDisplayPanel.Text += "1"; } so when I click button 1 thrice, the display panel will show "111". However, I only know how to add values to the display panel label. I tried -= but it wont work . The backspace button is supposed to remove the last value entered by the user but how do I do that ?

        M Offline
        M Offline
        Manas Bhardwaj
        wrote on last edited by
        #3

        Lim Yuxuan wrote:

        The backspace button is supposed to remove the last value entered by the user but how do I do that ?

        lblDisplayPanel.Text = lblDisplayPanel.Text.Remove(lblDisplayPanel.Text.Length - 1, 1);

        Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

        L 1 Reply Last reply
        0
        • W Willem Ten Broek

          Try the following in your back space button click event

          private void btnBS_Click(object sender, EventArgs e)
          {
          lblDisplayPanel.Text = lblDisplayPanel.Text.Remove(lblDisplayPanel.Text.Lemgth - 1);
          }

          L Offline
          L Offline
          Lim Yuxuan
          wrote on last edited by
          #4

          Thanks. I read the description of the remove method from the intellisense and it explains alot.

          1 Reply Last reply
          0
          • M Manas Bhardwaj

            Lim Yuxuan wrote:

            The backspace button is supposed to remove the last value entered by the user but how do I do that ?

            lblDisplayPanel.Text = lblDisplayPanel.Text.Remove(lblDisplayPanel.Text.Length - 1, 1);

            Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

            L Offline
            L Offline
            Lim Yuxuan
            wrote on last edited by
            #5

            Thanks. I have read the description of the remove method from the intellisense and it explains alot.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups