更改分隔符的蒙面文本文本、分隔符

2023-09-03 06:55:04 作者:安逸。

我试图用一个蒙面的文本框输入一个IP和数字目前正在用逗号分隔。有没有什么办法与点字符替换逗号?

这是我的蒙面文本框的定义至今:

  //
// txtIPAddressForSaving
//
this.txtIPAddressForSaving.Font =新System.Drawing.Font(Microsoft无衬线,30F);
this.txtIPAddressForSaving.Location =新System.Drawing.Point(148,115);
this.txtIPAddressForSaving.Mask =009.009.009.009;
this.txtIPAddressForSaving.Name =txtIPAddressForSaving;
this.txtIPAddressForSaving.PromptChar ='。';
this.txtIPAddressForSaving.Size =新System.Drawing.Size(463,53);
this.txtIPAddressForSaving.TabIndex = 13;
this.txtIPAddressForSaving.TabStop = FALSE;
 

解决方案

试试这个:

  this.txtIPAddressForSaving.Mask = @009 \ 0.009 \ 0.009 \ 0.009;
 
word中的 文本转表格 这个小技巧很好用的,快来试试吧

另一种选择是使用 InvariantCulture的的MaskedTextBox (保留旧的格式):

  txtIPAddressForSaving.Mask =009.009.009.009;
txtIPAddressForSaving.Culture = System.Globalization
                                      .CultureInfo.InvariantCulture;
 

需要注意的是,我们改变了文化的的MaskedTextBox 只适用与不适用任何其他控件。

I'm attempting to use a masked textbox to input an IP and the digits are currently being separated by a comma. Is there any way to replace the comma character with the dot character?

This is the definition of my masked textbox so far:

// 
// txtIPAddressForSaving
// 
this.txtIPAddressForSaving.Font = new System.Drawing.Font("Microsoft Sans Serif", 30F);
this.txtIPAddressForSaving.Location = new System.Drawing.Point(148, 115);
this.txtIPAddressForSaving.Mask = "009.009.009.009";
this.txtIPAddressForSaving.Name = "txtIPAddressForSaving";
this.txtIPAddressForSaving.PromptChar = '.';
this.txtIPAddressForSaving.Size = new System.Drawing.Size(463, 53);
this.txtIPAddressForSaving.TabIndex = 13;
this.txtIPAddressForSaving.TabStop = false;

解决方案

Try this:

this.txtIPAddressForSaving.Mask = @"009\.009\.009\.009";

Another option is to use InvariantCulture for your MaskedTextBox (keep the old format):

txtIPAddressForSaving.Mask = "009.009.009.009";
txtIPAddressForSaving.Culture = System.Globalization
                                      .CultureInfo.InvariantCulture;

Note that, the culture we change is applied only for the MaskedTextBox and doesn't apply any other controls.