<small id='7dXyM'></small><noframes id='7dXyM'>

      <bdo id='7dXyM'></bdo><ul id='7dXyM'></ul>
  1. <tfoot id='7dXyM'></tfoot>
    <i id='7dXyM'><tr id='7dXyM'><dt id='7dXyM'><q id='7dXyM'><span id='7dXyM'><b id='7dXyM'><form id='7dXyM'><ins id='7dXyM'></ins><ul id='7dXyM'></ul><sub id='7dXyM'></sub></form><legend id='7dXyM'></legend><bdo id='7dXyM'><pre id='7dXyM'><center id='7dXyM'></center></pre></bdo></b><th id='7dXyM'></th></span></q></dt></tr></i><div id='7dXyM'><tfoot id='7dXyM'></tfoot><dl id='7dXyM'><fieldset id='7dXyM'></fieldset></dl></div>
    <legend id='7dXyM'><style id='7dXyM'><dir id='7dXyM'><q id='7dXyM'></q></dir></style></legend>

      Winforms 将文本框格式化为货币

      Winforms Format TextBox To Currency(Winforms 将文本框格式化为货币)
            <tbody id='tSK4y'></tbody>
          1. <tfoot id='tSK4y'></tfoot>

              <small id='tSK4y'></small><noframes id='tSK4y'>

                <bdo id='tSK4y'></bdo><ul id='tSK4y'></ul>

                <i id='tSK4y'><tr id='tSK4y'><dt id='tSK4y'><q id='tSK4y'><span id='tSK4y'><b id='tSK4y'><form id='tSK4y'><ins id='tSK4y'></ins><ul id='tSK4y'></ul><sub id='tSK4y'></sub></form><legend id='tSK4y'></legend><bdo id='tSK4y'><pre id='tSK4y'><center id='tSK4y'></center></pre></bdo></b><th id='tSK4y'></th></span></q></dt></tr></i><div id='tSK4y'><tfoot id='tSK4y'></tfoot><dl id='tSK4y'><fieldset id='tSK4y'></fieldset></dl></div>
                <legend id='tSK4y'><style id='tSK4y'><dir id='tSK4y'><q id='tSK4y'></q></dir></style></legend>

                本文介绍了Winforms 将文本框格式化为货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我是 Winforms 开发的新手,我将在文本框中向我的用户显示数据.文本框将与货币数据绑定,因此我尝试格式化正在显示的值.

                I am new to Winforms development and I going to be displaying data to my users in a textbox. The textbox will be databound with data that is currency so I am trying to Format the value that is being displayed.

                我查看了一个蒙面文本框,但这并不是我想要的,因为它没有将美分放在小数点后.

                I looked at a Masked Text Box but that isn't exactly what I am looking for because it doesn't put the cents after the decimal.

                我需要为每个与此类似的文本框编码吗?

                Do I need to code for each textbox similar to this?

                TextBox.Text = DataSet.DataView[0].Amount.ToString("c");
                

                我有很多需要格式化的文本框,所以我想知道是否需要为每个文本框都这样做.有人有什么建议吗?

                I have alot of textboxes that need to be formatted so I am wondering if I need to do this for each one. Does anyone have any suggestions?

                推荐答案

                您可以创建自己的 TextBox 派生自标准文本框

                You can create your own TextBox derived from standard one

                 public class TextBoxEx : TextBox
                {
                    public string Format { get; set; }
                
                    private object datasource = new object();
                    public object Datasource
                    {
                        get { return datasource; }
                        set 
                        {
                            datasource = value;
                            if (datasource == null)
                                base.Text = string.Empty;
                            else if(string.IsNullOrWhiteSpace(Format))
                                base.Text = datasource.ToString();
                            else
                                base.Text = string.Format("{0:"+ Format + "}",datasource);
                        }
                    }
                }
                

                用法:

                   textbox.Format = "c";
                   textbox.Datasource = DataSet.DataView[0].Amount;
                

                这篇关于Winforms 将文本框格式化为货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)

                  <small id='pdBzG'></small><noframes id='pdBzG'>

                  • <i id='pdBzG'><tr id='pdBzG'><dt id='pdBzG'><q id='pdBzG'><span id='pdBzG'><b id='pdBzG'><form id='pdBzG'><ins id='pdBzG'></ins><ul id='pdBzG'></ul><sub id='pdBzG'></sub></form><legend id='pdBzG'></legend><bdo id='pdBzG'><pre id='pdBzG'><center id='pdBzG'></center></pre></bdo></b><th id='pdBzG'></th></span></q></dt></tr></i><div id='pdBzG'><tfoot id='pdBzG'></tfoot><dl id='pdBzG'><fieldset id='pdBzG'></fieldset></dl></div>

                      <legend id='pdBzG'><style id='pdBzG'><dir id='pdBzG'><q id='pdBzG'></q></dir></style></legend>
                          <tbody id='pdBzG'></tbody>
                          <bdo id='pdBzG'></bdo><ul id='pdBzG'></ul>
                          <tfoot id='pdBzG'></tfoot>