using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Net;
namespace System.IPCtrl
{
/// <summary>
/// IP地址输入控件 written by haipeng
/// </summary>
/// <summary>
/// 表示IP地址的类型为A、B、C或D类地址
/// </summary>
public enum IPType:byte{A,B,C,D};
public class IPbox : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox txt1;
private System.Windows.Forms.TextBox txt2;
private System.Windows.Forms.TextBox txt3;
private System.Windows.Forms.TextBox txt4;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public IPbox()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txt1 = new System.Windows.Forms.TextBox();
this.txt2 = new System.Windows.Forms.TextBox();
this.txt3 = new System.Windows.Forms.TextBox();
this.txt4 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txt1
//
this.txt1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txt1.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.txt1.Location = new System.Drawing.Point(2, 2);
this.txt1.MaxLength = 3;
this.txt1.Name = "txt1";
this.txt1.Size = new System.Drawing.Size(24, 16);
this.txt1.TabIndex = 0;
this.txt1.Text = "";
this.txt1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.txt1.LostFocus += new System.EventHandler(this.txt_LostFocus);
this.txt1.GotFocus += new System.EventHandler(this.txt_LostFocus);
this.txt1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt1_KeyPress);
//
// txt2
//
this.txt2.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txt2.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.txt2.Location = new System.Drawing.Point(34, 2);
this.txt2.MaxLength = 3;
this.txt2.Name = "txt2";
this.txt2.Size = new System.Drawing.Size(24, 16);
this.txt2.TabIndex = 1;
this.txt2.Text = "";
this.txt2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.txt2.LostFocus += new System.EventHandler(this.txt_LostFocus);
this.txt2.GotFocus += new System.EventHandler(this.txt_LostFocus);
this.txt2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt2_KeyPress);
//
// txt3
//
this.txt3.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txt3.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.txt3.Location = new System.Drawing.Point(66, 2);
this.txt3.MaxLength = 3;
this.txt3.Name = "txt3";
this.txt3.Size = new System.Drawing.Size(24, 16);
this.txt3.TabIndex = 2;
this.txt3.Text = "";
this.txt3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.txt3.LostFocus += new System.EventHandler(this.txt_LostFocus);
this.txt3.GotFocus += new System.EventHandler(this.txt_LostFocus);
this.txt3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt3_KeyPress);
//
// txt4
//
this.txt4.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txt4.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.txt4.Location = new System.Drawing.Point(98, 2);
this.txt4.MaxLength = 3;
this.txt4.Name = "txt4";
this.txt4.Size = new System.Drawing.Size(24, 16);
this.txt4.TabIndex = 3;
this.txt4.Text = "";
this.txt4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.txt4.LostFocus += new System.EventHandler(this.txt_LostFocus);
this.txt4.GotFocus += new System.EventHandler(this.txt_LostFocus);
this.txt4.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt4_KeyPress);
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(26, 2);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(8, 16);
this.label1.TabIndex = 7;
this.label1.Text = ".";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label2
//
this.label2.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(90, 2);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(8, 16);
this.label2.TabIndex = 8;
this.label2.Text = ".";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label3
//
this.label3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label3.Font = new System.Drawing.Font("SimSun", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.Location = new System.Drawing.Point(58, 2);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(8, 16);
this.label3.TabIndex = 9;
this.label3.Text = ".";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label4
//
this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label4.Font = new System.Drawing.Font("SimSun", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(0, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(122, 18);
this.label4.TabIndex = 10;
//
// IPbox
//
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txt4);
this.Controls.Add(this.txt3);
this.Controls.Add(this.txt2);
this.Controls.Add(this.txt1);
this.Controls.Add(this.label4);
this.Name = "IPbox";
this.Size = new System.Drawing.Size(124, 20);
this.Load += new System.EventHandler(this.UserControl1_Load);
this.ResumeLayout(false);
}
#endregion
private void UserControl1_Load(object sender, System.EventArgs e)
{
}
public void Clear()
{
this.txt1.Text="";
this.txt2.Text="";
this.txt3.Text="";
this.txt4.Text="";
}
private void txt1_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
string str=e.KeyChar.ToString();
if(e.KeyChar.ToString()=="." || e.KeyChar.ToString()=="。"||e.KeyChar.ToString()==" ")
{
if (txt1.SelectedText.ToString()=="" && txt1.Text.ToString()!="")
{
SendKeys.Send("{Tab}");
}
e.Handled=true;
return;
}
if (Regex.Match(e.KeyChar.ToString(),"[0-9]").Success)
{
if (txt1.Text.Length==2)
{
if(int.Parse(txt1.Text.ToString()+e.KeyChar.ToString())>255)
{
e.Handled=true;
}
else
{
txt2.Focus();
}
}
}
else
{
if(e.KeyChar.ToString()=="\b")
{
}
else
{
e.Handled=true;
}
}
}
catch
{
e.Handled=true;
}
}
private void txt2_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if(e.KeyChar.ToString()=="." || e.KeyChar.ToString()=="。"||e.KeyChar.ToString()==" ")
{
if (txt2.SelectedText.ToString()=="" && txt2.Text.ToString()!="")
{
SendKeys.Send("{Tab}");
}
e.Handled=true;return;
}
if (Regex.Match(e.KeyChar.ToString(),"[0-9]").Success)
{
if (txt2.Text.Length==2)
{
if(int.Parse(txt2.Text.ToString()+e.KeyChar.ToString())>255)
{
e.Handled=true;
}
else
{
txt3.Focus();
}
}
}
else
{
if(e.KeyChar.ToString()=="\b")
{
if(txt2.Text.ToString()=="")
{
txt1.Focus();
SendKeys.Send("{End}");
}
}
else
{
e.Handled=true;
}
}
}
catch
{
e.Handled=true;
}
}
private void txt3_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if(e.KeyChar.ToString()=="." || e.KeyChar.ToString()=="。"||e.KeyChar.ToString()==" ")
{
if (txt3.SelectedText.ToString()=="" && txt3.Text.ToString()!="")
{
SendKeys.Send("{Tab}");
}
e.Handled=true;return;
}
if (Regex.Match(e.KeyChar.ToString(),"[0-9]").Success)
{
if (txt3.Text.Length==2)
{
if(int.Parse(txt3.Text.ToString()+e.KeyChar.ToString())>255)
{
e.Handled=true;
}
else
{
txt4.Focus();
}
}
}
else
{
if(e.KeyChar.ToString()=="\b")
{
if(txt3.Text.ToString()=="")
{
txt2.Focus();
SendKeys.Send("{End}");
}
}
else
{
e.Handled=true;
}
}
}
catch
{
e.Handled=true;
}
}
private void txt4_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if(e.KeyChar.ToString()=="." || e.KeyChar.ToString()=="。"||e.KeyChar.ToString()==" ")
{
e.Handled=true;
}
if (Regex.Match(e.KeyChar.ToString(),"[0-9]").Success)
{
if (txt4.Text.Length==2)
{
if(int.Parse(txt4.Text.ToString()+e.KeyChar.ToString())>255)
{
e.Handled=true;
}
}
}
else
{
if(e.KeyChar.ToString()=="\b")
{
if(txt4.Text.ToString()=="")
{
txt3.Focus();
SendKeys.Send("{End}");
}
}
else
{
e.Handled=true;
}
}
}
catch
{
e.Handled=true;
}
}
private void txt_LostFocus(object sender, EventArgs e)
{
while(txt1.Text.Length>1 && txt1.Text.ToString().Substring(0,1)=="0")
{
txt1.Text=txt1.Text.ToString().Remove(0,1);
}
while(txt2.Text.Length>1 && txt2.Text.ToString().Substring(0,1)=="0")
{
txt2.Text=txt2.Text.ToString().Remove(0,1);
}
while(txt3.Text.Length>1 && txt3.Text.ToString().Substring(0,1)=="0")
{
txt3.Text=txt3.Text.ToString().Remove(0,1);
}
while(txt4.Text.Length>1 && txt4.Text.ToString().Substring(0,1)=="0")
{
txt4.Text=txt4.Text.ToString().Remove(0,1);
}
}
/// <summary>
/// 返回string类型的用户在IPBox控件中输入的IP地址
/// </summary>
override public string Text
{
get
{
return txt1.Text.ToString().Trim()+"."+txt2.Text.ToString().Trim()+"."+txt3.Text.ToString().Trim()+"."+txt4.Text.ToString().Trim();
}
set
{
try
{
string[] str=new string[4];
str=value.Split(char.Parse("."));
for(int i=0;i<4;i++)
{
if(int.Parse(str[i])>-1 && int.Parse(str[i])<256)
{
txt1.Text=str[0];
txt2.Text=str[1];
txt3.Text=str[2];
txt4.Text=str[3];
}
}
}
catch
{
}
}
}
/// <summary>
/// 返回System.Net.IPAddress类型的IP地址
/// </summary>
public IPAddress IPaddress
{
get
{
try
{
return IPAddress.Parse(this.Text.ToString());
}
catch
{
return IPAddress.Parse("0.0.0.0");
}
}
}
/// <summary>
/// 返回IP地址的类型(A,B,C,D),返回值为IPType类型
/// </summary>
public IPType Type
{
get
{
if (int.Parse(this.txt1.Text.ToString().Trim())<128)
{
return IPType.A;
}
else
{
if (int.Parse(this.txt1.Text.ToString().Trim())<192)
{
return IPType.B;
}
else
{
if(int.Parse(this.txt1.Text.ToString().Trim())<224)
{
return IPType.C;
}
else
{
return IPType.D;
}
}
}
}
}
public BorderStyle BorderStyle
{
get
{
return this.label4.BorderStyle;
}
set
{
try
{
this.label4.BorderStyle=value;
}
catch
{
}
}
}
}
}
相关推荐
Field0~Field3:是四个IP段; IP:是IP地址的值; Field0Range~Field3Range:是四个IP段的限制范围; 其它的属性和VCL其它控件是一样的。
confirm对话框类,msgshow(ByVal handle As System.Web.UI.Page, ByVal js_fuc_name As String, ByVal btn_ok As String, ByVal btn_cancel As String);handle调用该类的页面句柄,js_fuc_name 自动生成JS函数的...
给和我一样还在摸索道路上的菜鸟们提供的一个下拉列表中有删除图片的组合框类的例子。附带IP地址格式化显示功能,使用前请务必查看ReadMe.txt文件。。。
CIconListBox带图标的列表框类 http://blog.csdn.net/akof1314/archive/2010/11/08/5994830.aspx
主要介绍了几种常用对话框
一个ip地址格式输入框类,可以直接调用new 对象,IpAddressField ipAddrFld = new IpAddressField();
个人编写的编辑框类,派生自CEdit类, 可实现控制文本框只接受浮点数输入,而不接受非法字符 不当之处,恳请指正~
C#开发简单的按钮类、窗体类、输入框类等组件的封装。
建立一个单文档mfc程序,设计一个菜单按钮,可以弹出一个对话框。在对话框中使用视图类和框架类中的变量。说明:http://blog.csdn.net/tywwwww/article/details/55281565
改变控件的字体颜色和背景色 在对话框类中添加变量: HBRUSH m_hBrush=CreateSolidBrush(RGB(0,0,0)); //用所需的背景色定义画刷 用建立类向导为对话框添加OnCtlColor函数: HBRUSH CListBkChangeDlg::OnCtlColor...
QT 4.7.4Qt自定义/自绘复选框/单选框类,按钮状态有:正常状态,鼠标移动状态,鼠标按下状态,鼠标释放状态暂定为与正常状态相同。可以设置按钮上文本或不显示文本,按钮自适应图片大小或图片自适应按钮大小,使能/...
使用标准输入对话框这次演示一下使用标准输入框QInputDialog,QInputDialog类目前提供了4中数据类型的输入:字符串,Int数据,double类数据,下拉列表框。
DLL输出对话框类的例子解压密码:hur.cn或vip.hur.cn.rar
http://blog.csdn.net/wlsgzl/article/details/8502106 之前有人问有没有教程的代码,我就花时间写了个简单的。
Qt制作的密码框类
超级加密 3000一款功能强大的文件加密和文件夹加密软件。主要针对于进常对重要文件加密和文件夹加密的用户。该软件有超快和最强的文件加密、文件夹加密功能,采用先进的加密算法,使你的文件加密和文件夹加密后,...
一个比较好用的VC对话框类,比较有用,在一些工程项目中可以参考使用
一个用VC++写的编辑框类,为大家学习vc++提供参考
第4讲 对话框的界面世界 摘要 本讲先来讨论对话框界面设计的一般过程和技巧,然后...所谓"控件",是指具有一定功能的界面单元,如按钮、编辑框、列表框、组合框等。在这里,我们先来讨论对话框的界面设计过程。
普通的asp.net 2.0应用程序中,如果需要弹出一个对话框,可以使用 Response.Write("<script>alert('弹出一个对话框');</script>"); 在ajax页面中,不能使用上述方法,但是在AJAX中的ScriptManager却提供了弹出...