masked textbox
-
My question is based on functionality in Masked Textbox control which is available only in .Net framework 2.0 onwards. I want the kind of functionality provided by MaskedTextbox control but I can't use this control as I'm currently working on framework 1.1. So I have decided to make one for me on my own. I derived the control from Text box. I was able to implement Mask dialog and validations but stuck up with text property implementation of control. For the Masked Textbox, if you implement telephone no. mask with format (___)___-____, then text property value initially will be blank. But on the form, Masked TextBox text will show format i.e. "(___)___-____". Also, if I write 333 in property grid for text property then in property Grid I will be able to see value as "333" while in the Control on the form it will display me a text like "(333)___-____". So in a way two different values for the same text property in property grid and control. So this is bit confusing and don't know how to implement this thing in a same way as provided by Masked Text box. I tried to implement this by overriding the text property and giving different implementation for design time and run time. But its not helping me. Can anyone help me by providing some ideas on how to do above things. I hope I'm clear with my question. If reading above, you are not clear about the question pls write back to me or check the working of Masked Textbox control for better understanding. Regards, KC
-
My question is based on functionality in Masked Textbox control which is available only in .Net framework 2.0 onwards. I want the kind of functionality provided by MaskedTextbox control but I can't use this control as I'm currently working on framework 1.1. So I have decided to make one for me on my own. I derived the control from Text box. I was able to implement Mask dialog and validations but stuck up with text property implementation of control. For the Masked Textbox, if you implement telephone no. mask with format (___)___-____, then text property value initially will be blank. But on the form, Masked TextBox text will show format i.e. "(___)___-____". Also, if I write 333 in property grid for text property then in property Grid I will be able to see value as "333" while in the Control on the form it will display me a text like "(333)___-____". So in a way two different values for the same text property in property grid and control. So this is bit confusing and don't know how to implement this thing in a same way as provided by Masked Text box. I tried to implement this by overriding the text property and giving different implementation for design time and run time. But its not helping me. Can anyone help me by providing some ideas on how to do above things. I hope I'm clear with my question. If reading above, you are not clear about the question pls write back to me or check the working of Masked Textbox control for better understanding. Regards, KC
Hello, I think in that case only a workaround does the trick! Because Text property of TextBox seems to be special case. Therefore I would use an additional "newText" property and hide the "Text" property.
private string \_newText=""; \[DefaultValue("")\] public string NewText { get { return \_newText; } set { if(value!=\_newText) { \_newText = value; Text = \_newText+" I'm formated"; } } } \[Browsable(false)\] public new string Text { get { return base.Text; } set { if(value!=base.Text) { base.Text = value; } } }
Hope it helps!
All the best, Martin