开发者

C# Windows form text box format with data binding

开发者 https://www.devze.com 2023-03-23 06:55 出处:网络
I have a wi开发者_C百科ndows form with a text box: txtMyText. txtMyText.Text is Bound to a data source: long lMyLongValue.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消