Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi currently I'm working on a Point of sale software in c# with SQL Server I just make a form to receive the Invoice amount in this screen cashier enters the paid amount.
but I did not know how can I add auto point function just like a cash register,
let suppose cashir want to enter 180.78 but i want
if the user press 1 then in the text box it write 0.01
when the user press 5 then 0.15
and when the user press 0 the 1.50
when the user press 7 then 15.07
when the user press 8 then 180.78 etc
I hope you understand my condition please any one tell me how can I achieve this,
thanks in advance

What I have tried:

i dont know how can i do this, please any one suggestion me any method
Posted
Updated 6-Nov-21 10:30am

You can use the Masked Textbox for this with the RightToLeft property set to yes, see:
How to Mask input in MaskedTextBox in C#? - GeeksforGeeks[^]

But you probably want to write your own custom control, here is an example:
Masked C# TextBox Control[^]
 
Share this answer
 
v3
Comments
BillWoodruff 6-Nov-21 17:34pm    
+5
You will need the TextChanged event.
A regular textbox takes a bit of string manipulation, something like this:

private void tb_TextChanged(object sender, EventArgs e) {
	string s = tb.Text;
	s = "000"+s.Replace(".", "");
	int len = s.Length;
	s = s.Substring(0, len-2).TrimStart('0').PadLeft(1, '0')+
		"."+s.Substring(len-2,2);
	tb.Text = s;
	tb.SelectionStart = s.Length;
	tb.SelectionLength = 0;
}


notes:
- textbox can initially be empty (does not need to be initialized to 0.00)
- does not rely on numeric conversions, so no range limitations
- works also when something gets pasted in
- does not reject unexpected characters (if needed, extra code should be added)
- textbox cursor is forced to the right
- fortunately this event only fires when the content really changes, so no event avalanche (unless the event handlers code isn't stable)
- during development it is wise to add logging and to apply a simple defense, e.g.

private void tb_TextChanged(object sender, EventArgs e) {
	if (++changes>10) return;
	Console.WriteLine(tb.Text);
	...
}
 
Share this answer
 
v4

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