VB2010的控件面板上有MaskedTextBox,可将其Mask属性设置为000.000.000.000,即可输入IP地址,但是实际使用中,总觉得与系统中网卡IP地址输入框相去甚远,因此采用四个文本框和四个标签控件(用于显示小数点)组合,制作一个类似的IP地址输入框控件。
新建一个类,命名为IpBox,代码如下:
Public Class IpBox
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents textBox3 As System.Windows.Forms.TextBox
Friend WithEvents label3 As System.Windows.Forms.Label
Friend WithEvents textBox4 As System.Windows.Forms.TextBox
Friend WithEvents label1 As System.Windows.Forms.Label
Friend WithEvents textBox1 As System.Windows.Forms.TextBox
Friend WithEvents label2 As System.Windows.Forms.Label
Friend WithEvents textBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel
Me.textBox3 = New System.Windows.Forms.TextBox
Me.label3 = New System.Windows.Forms.Label
Me.textBox4 = New System.Windows.Forms.TextBox
Me.label1 = New System.Windows.Forms.Label
Me.textBox1 = New System.Windows.Forms.TextBox
Me.label2 = New System.Windows.Forms.Label
Me.textBox2 = New System.Windows.Forms.TextBox
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.SystemColors.Window
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel1.Controls.Add(Me.textBox3)
Me.Panel1.Controls.Add(Me.label3)
Me.Panel1.Controls.Add(Me.textBox4)
Me.Panel1.Controls.Add(Me.label1)
Me.Panel1.Controls.Add(Me.textBox1)
Me.Panel1.Controls.Add(Me.label2)
Me.Panel1.Controls.Add(Me.textBox2)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(