我正在尝试使用带遮罩的文本框输入IP,并且数字当前由逗号分隔。有什么方法可以将点号替换为逗号?
到目前为止,这是我屏蔽的文本框的定义:
//
// 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;
最佳答案
尝试这个:
this.txtIPAddressForSaving.Mask = @"009\.009\.009\.009";
另一种选择是对
InvariantCulture
使用MaskedTextBox
(保留旧格式):txtIPAddressForSaving.Mask = "009.009.009.009";
txtIPAddressForSaving.Culture = System.Globalization
.CultureInfo.InvariantCulture;
请注意,我们更改的区域性仅适用于
MaskedTextBox
,不适用任何其他控件。