三级片快播 Winform中使用MaskedTextBox制作IP地址输入框

发布日期:2024-12-22 08:07    点击次数:122

三级片快播 Winform中使用MaskedTextBox制作IP地址输入框

环境:C/S Winform C#三级片快播

Demo:

图片

功能:自动建造ip掩码,输入形如999.999.999.999的花样,并建造keydown事件,当输入.的技艺,自动跳至下一栏。

步伐:

1,从器具箱中拖入一个MaskedTextBox,定名为txtPACSIP;

2,在mask属性中,输入:999.999.999.999

国产人兽

3,在prompt属性中,将_换为空格。如若你心爱_的话,也不错无谓换。

4,创建KeyDown事件,附以下代码:

private void txtPACSIP_KeyDown(object sender, KeyEventArgs e)
 {
  if (e.KeyCode == Keys.Decimal)
  {
   int pos = txtPACSIP.SelectionStart;
   int max = (txtPACSIP.MaskedTextProvider.Length - txtPACSIP.MaskedTextProvider.EditPositionCount);
   int nextField = 0;
 
   for (int i = 0; i < txtPACSIP.MaskedTextProvider.Length; i++)
   {
 if (!txtPACSIP.MaskedTextProvider.IsEditPosition(i) && (pos + max) >= i)
  nextField = i;
   }
   nextField += 1;
 
   // We're done, enable the TabStop property again   
 
 
   txtPACSIP.SelectionStart = nextField;
 
  }
 }

固然, 你如若念念将tab键也竣事自动跳至下一栏的话,多加个条目就行。

5,在取值的进程中,记起要replace空格:

PingReply reply = p1.Send(this.txtPACSIP.Text.Replace(" ",""));

本站仅提供存储工作,通盘实质均由用户发布,如发现存害或侵权实质,请点击举报。