Mask the TextBox
-
Hello, I would like to mask the text box such that it would only be for the money amounts, and it would have $ sign in front. So for input in textbox: 4500 Masked to: $ 4,500 Any ideas? Thank you.
-
Hello, I would like to mask the text box such that it would only be for the money amounts, and it would have $ sign in front. So for input in textbox: 4500 Masked to: $ 4,500 Any ideas? Thank you.
This the modification version of MaskedTextControl from User Interfaces in C# book
using System; using System.Windows.Forms; public class MaskedTextBox : TextBox { private string mask; public string Mask { get { return mask; } set { mask = value; this.Text = ""; } } Protected override void OnKeyPress(KeyPressEventArgs e) { if (Mask != "") { e.Handled = true; string newText = this.Text; bool finished = false; for (int i = this.SelectionStart; i < mask.Length; i++) { switch (mask[i].ToString()) { case "#" : if (Char.IsDigit(e.KeyChar) ) { if(this.TextLength
In the Form Load event add the following maskTextBox.Mask = "$###,###"; MCAD
-
This the modification version of MaskedTextControl from User Interfaces in C# book
using System; using System.Windows.Forms; public class MaskedTextBox : TextBox { private string mask; public string Mask { get { return mask; } set { mask = value; this.Text = ""; } } Protected override void OnKeyPress(KeyPressEventArgs e) { if (Mask != "") { e.Handled = true; string newText = this.Text; bool finished = false; for (int i = this.SelectionStart; i < mask.Length; i++) { switch (mask[i].ToString()) { case "#" : if (Char.IsDigit(e.KeyChar) ) { if(this.TextLength
In the Form Load event add the following maskTextBox.Mask = "$###,###"; MCAD
There seems to be an error: if(this.TextLength { in this line, the IF statement is not completed, or am I reading it incorectly? Is it: if (this.TextLength != 0) Another thing, to make the amount bigger, do I just increase the mask line: "$###,###,###....", or there is a better way? Thank you
-
There seems to be an error: if(this.TextLength { in this line, the IF statement is not completed, or am I reading it incorectly? Is it: if (this.TextLength != 0) Another thing, to make the amount bigger, do I just increase the mask line: "$###,###,###....", or there is a better way? Thank you
sorry some thing wrong was happend replace
if(this.TextLength {
with if(this.TextLength<mask.Length) This prevent the user form enter number longer than mask lenght **zaboboa wrote:** _Another thing, to make the amount bigger, do I just increase the mask line: "$###,###,###....", or there is a better way?_ Yes you cab write mask like $###,###,### or even $(###)(###),(###) **Note**:this quick code so test it before you use it and you may add another thibgs like backspace... MCAD
-
sorry some thing wrong was happend replace
if(this.TextLength {
with if(this.TextLength<mask.Length) This prevent the user form enter number longer than mask lenght **zaboboa wrote:** _Another thing, to make the amount bigger, do I just increase the mask line: "$###,###,###....", or there is a better way?_ Yes you cab write mask like $###,###,### or even $(###)(###),(###) **Note**:this quick code so test it before you use it and you may add another thibgs like backspace... MCAD
You know, it will work better if you put this statement insted if(this.TextLength == this.SelectionStart) Of course for this mask to be perfect you have to add a Leave event, in case the user leaves the box, with the input like that $455,6 Thank you for your help, it gave me a big jumpstart.
-
You know, it will work better if you put this statement insted if(this.TextLength == this.SelectionStart) Of course for this mask to be perfect you have to add a Leave event, in case the user leaves the box, with the input like that $455,6 Thank you for your help, it gave me a big jumpstart.
zaboboa wrote: Of course for this mask to be perfect you have to add a Leave event, in case the user leaves the box, with the input like that $455,6 And Copy and Paste there are many things you can add it Go on MCAD