你的位置:AG庄闲游戏官网首页 > 联系方式 > AG庄闲游戏APP Winform中使用MaskedTextBox制作IP地址输入框

AG庄闲游戏APP Winform中使用MaskedTextBox制作IP地址输入框

时间:2026-01-14 03:45 点击:131 次

AG庄闲游戏APP Winform中使用MaskedTextBox制作IP地址输入框

环境:C/S Winform C#

Demo:

图片

功能:自动设置ip掩码,输入形如999.999.999.999的格式,并设置keydown事件,当输入.的时候,自动跳至下一栏。

方法:

1,从工具箱中拖入一个MaskedTextBox,命名为txtPACSIP;

{jz:field.toptypename/}

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

3,在prompt属性中,将_换为空格。如果你喜欢_的话,AG庄闲和游戏也可以不用换。

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

{jz:field.toptypename/}

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空格:

建站客服QQ:88888888

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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。
服务热线
官方网站:wujunyong.com
工作时间:周一至周六(09:00-18:00)
联系我们
QQ:2852320325
邮箱:wujunyong.com @qq.com
地址:武汉东湖新技术开发区光谷大道国际企业中心
关注公众号
ag国际手机App

Copyright © 1998-2026 AG庄闲游戏官网首页™版权所有

wujunyong.com 备案号 备案号: 京ICP备12023939号-42

技术支持:®ag国际   RSS地图 HTML地图

回到顶部