C# Windows form text box format with data binding
I have a wi开发者_C百科ndows form with a text box: txtMyText.
txtMyText.Text is Bound to a data source: long lMyLongValue.
On the form I would like the value to display as a six digit value with leading zeros. Example 000123.
How can this be accomplished?
I believe Binding.Format event, can be pretty suitable for your needs, if not, you can bind it not to long
property, but to string
property and handle conversion from long
-> srtring
and vice versa "by hand".
for convert it into formatted string use pretty simple example:
long l =13;
string sformat = l.ToString("000000"); // 000013
Regards.
Yes, follow link How to: Pad a Number with Leading Zeros
精彩评论