开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜