Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is the code where by I want to add 10G to the textbox but want to make sure that the user can edit the number of grams but never touch the G or even better when it reaches 1000 it becomes a KG much help would be appreciated my textbox name is called flourmaskedtextbox
and when they press the minus button same thing happens as well

What I have tried:

flourCalculator();
          string digits = new string(flourString.TakeWhile(c => Char.IsDigit(c)).ToArray());
          int flourintnumbers;
          if (Int32.TryParse(digits, out flourintnumbers))
          {
              Console.WriteLine(flourintnumbers);
              flourintnumbers = flourintnumbers + 10;
              flourString = flourintnumbers.ToString() + "g";
              flourMaskedTextBox.Text = flourString;

              //is to retrieve text from textbox and convert to integer
Posted
Updated 3-Feb-21 19:44pm
Comments
Peter_in_2780 4-Feb-21 0:24am    
Just a suggestion. Separate the numbers and units into two adjacent textboxes.

1 solution

You could do it like this:
this.maskedTextBox1.Text = "1";
this.maskedTextBox1.Mask = "00000kg";
 
Share this answer
 
v2
Comments
Member 13566383 4-Feb-21 16:13pm    
The symbol for grams is g and not G. G stands for Gauss, an old unit for magnetic flux density no longer in use. And the symbol for kilo is k and not K. K stands for Kelvin.
So KG for me reads as Kelvin-Gauss.
RickZeeland 5-Feb-21 1:34am    
You are correct! updated the solution :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900