Need help with Backspace button!!
-
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 ?
-
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 ?
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);
} -
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 ?
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.
-
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);
}Thanks. I read the description of the remove method from the intellisense and it explains alot.
-
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.
Thanks. I have read the description of the remove method from the intellisense and it explains alot.