最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WinForm IP地址輸入框控件實(shí)現(xiàn)

 更新時(shí)間:2018年05月08日 11:53:37   作者:zf15256888839  
這篇文章主要為大家詳細(xì)介紹了WinForm IP地址輸入框控件的實(shí)現(xiàn)代碼,基于VS2010模擬windows系統(tǒng)自帶IP輸入框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了WinForm IP地址輸入框控件的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

IPInput.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace IPInputControl.Ctrl
{
 public partial class IPInput : UserControl
 {
 public IPInput()
 {
  InitializeComponent();
 }
 TextBox ParentTxt;
 private void IPInput_Load(object sender, EventArgs e)
 {
  ParentTxt = txt_1;
 }
 public void txt_KeyDown(object sender, KeyEventArgs e)
 {
  ParentTxt = (TextBox)sender;
  if (e.KeyCode == Keys.Left)
  {
  switch (ParentTxt.Name.Split('_')[1])
  {
   case "1":
   break;
   case "2":
   if (ParentTxt.SelectionStart == 0 && ParentTxt.Text != "")
   {
    if (int.Parse(ParentTxt.Text) > 255)
    {
    MessageBox.Show(ParentTxt.Text + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和255之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    ParentTxt.Text = "255";
    ParentTxt.SelectionStart = 0;
    }
    else
    {
    txt_1.Focus();
    }
   }
   else if (ParentTxt.Text == "")
   {
    txt_1.Focus();
   }
   break;
   case "3":
   if (ParentTxt.SelectionStart == 0 && ParentTxt.Text != "")
   {
    if (int.Parse(ParentTxt.Text) > 255)
    {
    MessageBox.Show(ParentTxt.Text + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和255之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    ParentTxt.Text = "255";
    ParentTxt.SelectionStart = 0;
    }
    else
    {
    txt_2.Focus();
    }
   }
   else if (ParentTxt.Text == "")
   {
    txt_2.Focus();
   }
   break;
   case "4":
   if (ParentTxt.SelectionStart == 0 && ParentTxt.Text != "")
   {
    if (int.Parse(ParentTxt.Text) > 255)
    {
    MessageBox.Show(ParentTxt.Text + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和255之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    ParentTxt.Text = "255";
    ParentTxt.SelectionStart = 0;
    }
    else
    {
    txt_3.Focus();
    }
   }
   else if (ParentTxt.Text == "")
   {
    txt_3.Focus();
   }
   break;
  }
  }
  else if (e.KeyCode == Keys.Right)
  {
  switch (ParentTxt.Name.Split('_')[1])
  {
   case "1":
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length && ParentTxt.Text != "")
   {
    if (int.Parse(ParentTxt.Text) > 223)
    {
    MessageBox.Show(ParentTxt.Text + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和223之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    ParentTxt.Text = "223";
    ParentTxt.SelectionStart = ParentTxt.Text.Length;
    }
    else
    {
    txt_2.Focus();
    }
   }
   else if (ParentTxt.Text == "")
   {
    txt_2.Focus();
   }
   break;
   case "2":
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length && ParentTxt.Text != "")
   {
    if (int.Parse(ParentTxt.Text) > 255)
    {
    MessageBox.Show(ParentTxt.Text + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和255之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    ParentTxt.Text = "255";
    ParentTxt.SelectionStart = ParentTxt.Text.Length;
    }
    else
    {
    txt_3.Focus();
    }
   }
   else if (ParentTxt.Text == "")
   {
    txt_3.Focus();
   }
   break;
   case "3":
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length && ParentTxt.Text != "")
   {
    if (int.Parse(ParentTxt.Text) > 255)
    {
    MessageBox.Show(ParentTxt.Text + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和255之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    ParentTxt.Text = "255";
    ParentTxt.SelectionStart = ParentTxt.Text.Length;
    }
    else
    {
    txt_4.Focus();
    }
   }
   else if (ParentTxt.Text == "")
   {
    txt_4.Focus();
   }
   break;
   case "4":
   break;
  }
  }
 }
 public void txt_KeyPress(object sender, KeyPressEventArgs e)
 {
  ParentTxt = (TextBox)sender;
  Regex regex = new Regex(@"^[0-9]+$");
  if (!regex.IsMatch(e.KeyChar.ToString()) && e.KeyChar != (Char)Keys.Back)
  {
  e.Handled = true;
  }
  else if (e.KeyChar == (Char)Keys.Back)
  {
  e.Handled = false;
  switch (ParentTxt.Name.Split('_')[1])
  {
   case "1":
   break;
   case "2":
   if (ParentTxt.SelectionStart == 0)
   {
    txt_1.Focus();
    if (txt_1.Text != "")
    {
    txt_1.Text = txt_1.Text.Substring(0, txt_1.Text.Length - 1);
    }
    txt_1.SelectionStart = txt_1.Text.Length;
   }
   break;
   case "3":
   if (ParentTxt.SelectionStart == 0)
   {
    txt_2.Focus();
    if (txt_2.Text != "")
    {
    txt_2.Text = txt_2.Text.Substring(0, txt_2.Text.Length - 1);
    }
    txt_2.SelectionStart = txt_2.Text.Length;
   }
   break;
   case "4":
   if (ParentTxt.SelectionStart == 0)
   {
    txt_3.Focus();
    if (txt_3.Text != "")
    {
    txt_3.Text = txt_3.Text.Substring(0, txt_3.Text.Length - 1);
    }
    txt_3.SelectionStart = txt_3.Text.Length;
   }
   break;
  }
  }
  else
  {
  switch (ParentTxt.Name.Split('_')[1])
  {
   case "1":
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length)
   {
    if (int.Parse(ParentTxt.Text + e.KeyChar.ToString()) > 223)
    {
    MessageBox.Show(ParentTxt.Text + e.KeyChar.ToString() + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和223之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    e.Handled = true;
    ParentTxt.Text = "223";
    }
    else
    {
    e.Handled = false;
    }
   }
   else if(ParentTxt.Text.Length != 3)
   {
    e.Handled = false;
   }
   else
   {
    e.Handled = true;
   }
   break;
   default:
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length)
   {
    if (int.Parse(ParentTxt.Text + e.KeyChar.ToString()) > 255)
    {
    MessageBox.Show(ParentTxt.Text + e.KeyChar.ToString() + "不是有效項(xiàng)。請(qǐng)指定一個(gè)介于1和255之間的值。", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    e.Handled = true;
    ParentTxt.Text = "255";
    }
    else
    {
    e.Handled = false;
    }
   }
   else if (ParentTxt.Text.Length != 3)
   {
    e.Handled = false;
   }
   else
   {
    e.Handled = true;
   }
   break;
  }
  }
 }
 public void txt_TextChanged(object sender, EventArgs e)
 {
  if (ParentTxt.Text.Length == 3)
  {
  switch (ParentTxt.Name.Split('_')[1])
  {
   case "1":
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length)
   {
    txt_2.Focus();
   }
   break;
   case "2":
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length)
   {
    txt_3.Focus();
   }
   break;
   case "3":
   if (ParentTxt.SelectionStart == ParentTxt.Text.Length)
   {
    txt_4.Focus();
   }
   break;
   case "4":
   break;
  }
  }
 }
 }
}

ControlText.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace IPInputControl.Ctrl
{
 public partial class ControlText : TextBox
 {
 public ControlText()
 {
  InitializeComponent();
 }
 public void txt_TextChange(object sender, EventArgs e)
 {
  if (this.Text.Length == 3)
  {
  SendKeys.Send("{TAB}");
  }
 }
 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
 {
  if (keyData == Keys.Tab)
  {
  return true;
  }
  return base.ProcessCmdKey(ref msg, keyData);
 }
 }
}

更多完整代碼請(qǐng)點(diǎn)擊下載:WinForm IP地址輸入框控件

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • unity實(shí)現(xiàn)繪畫(huà)功能

    unity實(shí)現(xiàn)繪畫(huà)功能

    這篇文章主要為大家詳細(xì)介紹了unity實(shí)現(xiàn)繪畫(huà)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • WPF開(kāi)發(fā)技巧之花式控件功能擴(kuò)展詳解

    WPF開(kāi)發(fā)技巧之花式控件功能擴(kuò)展詳解

    這篇文章主要給大家介紹了關(guān)于WPF日常開(kāi)發(fā)之花式控件功能擴(kuò)展的相關(guān)資料,通過(guò)文中這個(gè)例子,我們可以對(duì)WPF的掌握會(huì)更深刻,需要的朋友可以參考下
    2021-07-07
  • 深入多線程之:解析線程的交會(huì)(Thread Rendezvous)詳解

    深入多線程之:解析線程的交會(huì)(Thread Rendezvous)詳解

    本篇文章是對(duì)線程的交會(huì)(Thread Rendezvous)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • C#實(shí)現(xiàn)嵌套循環(huán)的示例代碼

    C#實(shí)現(xiàn)嵌套循環(huán)的示例代碼

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)嵌套循環(huán)的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-09-09
  • 深入c# GDI+簡(jiǎn)單繪圖的具體操作步驟(三)

    深入c# GDI+簡(jiǎn)單繪圖的具體操作步驟(三)

    前兩篇已經(jīng)基本向大家介紹了繪圖的基本知識(shí).那么,我就用我們上兩篇所學(xué)的,做幾個(gè)例子.我們先來(lái)做一個(gè)簡(jiǎn)單的--仿QQ截圖
    2013-05-05
  • C#中BackgroundWorker類(lèi)用法總結(jié)

    C#中BackgroundWorker類(lèi)用法總結(jié)

    本文詳細(xì)講解了C#中BackgroundWorker類(lèi)用法總結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • WPF實(shí)現(xiàn)控件拖動(dòng)的示例代碼

    WPF實(shí)現(xiàn)控件拖動(dòng)的示例代碼

    這篇文章主要介紹了WPF實(shí)現(xiàn)控件拖動(dòng)的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • C#特性之匿名方法和Lambda表達(dá)式

    C#特性之匿名方法和Lambda表達(dá)式

    這篇文章主要介紹了C#特性之匿名方法和Lambda表達(dá)式,需要的朋友可以參考下
    2014-12-12
  • C#使用WMI獲取硬盤(pán)參數(shù)的實(shí)現(xiàn)方法

    C#使用WMI獲取硬盤(pán)參數(shù)的實(shí)現(xiàn)方法

    因?yàn)樾枨笮枰婕矮@取硬盤(pán)的SN參數(shù),但是又不想要獲取到U盤(pán)或移動(dòng)硬盤(pán)設(shè)備的SN,所以就淺淺的研究了一下,本文給大家介紹了C#使用WMI獲取硬盤(pán)參數(shù)的實(shí)現(xiàn)方法,需要的朋友可以參考下
    2024-06-06
  • Unity存儲(chǔ)游戲數(shù)據(jù)的多種方法小結(jié)

    Unity存儲(chǔ)游戲數(shù)據(jù)的多種方法小結(jié)

    這篇文章主要介紹了Unity存儲(chǔ)游戲數(shù)據(jù)的幾種方法,在游戲開(kāi)發(fā)中,存儲(chǔ)游戲數(shù)據(jù)是非常重要的,因?yàn)橛螒驍?shù)據(jù)決定了游戲的各個(gè)方面,例如游戲的進(jìn)度、玩家的成就、游戲的設(shè)置,需要的朋友可以參考下
    2023-02-02

最新評(píng)論

尼木县| 丹江口市| 额尔古纳市| 九江县| 色达县| 孟州市| 象州县| 舞钢市| 北京市| 伽师县| 淄博市| 壶关县| 聊城市| 共和县| 横山县| 衡南县| 巩留县| 乐清市| 澜沧| 桦川县| 岚皋县| 噶尔县| 长乐市| 奎屯市| 西吉县| 固镇县| 信丰县| 麟游县| 奇台县| 景宁| 华蓥市| 嘉义市| 清河县| 吉林省| 融水| 纳雍县| 张掖市| 霍城县| 安阳市| 甘南县| 北京市|