Click here to Skip to main content
15,891,895 members
Articles / Programming Languages / Visual Basic

IP Address, Port Number, Subnet Mask Submission Form Library

Rate me:
Please Sign up or sign in to vote.
3.42/5 (5 votes)
18 Mar 20034 min read 230.6K   3.1K   60  
A class library for an easy submission of IP Address, Port Number and Subnet Mask
  • liquidforms_src.zip
    • LiquidForms_src
      • AssemblyInfo.cs
      • bin
        • Debug
          • GD.NetworkMngr.dll
          • GD.NetworkMngr.pdb
          • LiquidForms.dll
          • LiquidForms.pdb
      • FrmBase
      • FrmCommon
      • iFrm.cs
      • Images.resources
      • LiquidForms.csproj
      • liquidForms.csproj.user
      • liquidForms.sln
      • liquidForms.suo
      • obj
        • Debug
          • GD.Forms.dll
          • GD.Forms.dll.incr
          • GD.Forms.exe
          • GD.Forms.exe.incr
          • GD.Forms.FrmDialog.resources
          • GD.Forms.FrmRoot.resources
          • GD.Forms.pdb
          • GD.Forms.projdata
          • GDForms.dll
          • GDForms.dll.incr
          • GDForms.exe
          • GDForms.exe.incr
          • GDForms.FrmCommon.FrmIPSubnet.resources
          • GDForms.FrmDialog.resources
          • GDForms.FrmRoot.resources
          • GDForms.pdb
          • GDForms.projdata
          • GDForms.projdata1
          • LiquidForms.dll
          • LiquidForms.dll.incr
          • LiquidForms.exe
          • LiquidForms.exe.incr
          • LiquidForms.FrmBase.FrmDialog.resources
          • LiquidForms.FrmBase.FrmRoot.resources
          • LiquidForms.FrmCommon.FrmIPSubnet.resources
          • LiquidForms.pdb
          • liquidForms.projdata
      • ResGFX
        • Blank.ico
  • liquidforms_demo.zip
    • LiquidForms
      • AssemblyInfo.cs
      • bin
        • Debug
          • GD.NetworkMngr.dll
          • GD.NetworkMngr.pdb
          • LiquidForms.exe
          • LiquidForms.pdb
      • FrmBase
      • FrmCommon
      • iFrm.cs
      • Images.resources
      • LiquidForms.csproj
      • liquidForms.csproj.user
      • liquidForms.sln
      • liquidForms.suo
      • obj
        • Debug
          • GD.Forms.dll
          • GD.Forms.dll.incr
          • GD.Forms.exe
          • GD.Forms.exe.incr
          • GD.Forms.FrmDialog.resources
          • GD.Forms.FrmRoot.resources
          • GD.Forms.pdb
          • GD.Forms.projdata
          • GDForms.dll
          • GDForms.dll.incr
          • GDForms.exe
          • GDForms.exe.incr
          • GDForms.FrmCommon.FrmIPSubnet.resources
          • GDForms.FrmDialog.resources
          • GDForms.FrmRoot.resources
          • GDForms.pdb
          • GDForms.projdata
          • GDForms.projdata1
          • LiquidForms.exe
          • LiquidForms.exe.incr
          • LiquidForms.FrmBase.FrmDialog.resources
          • LiquidForms.FrmBase.FrmRoot.resources
          • LiquidForms.FrmCommon.FrmIPSubnet.resources
          • LiquidForms.pdb
          • liquidForms.projdata
      • ResGFX
        • Blank.ico
      • TestForms.cs
/*
 * Program			: LiquidForms
 * Author			: Christian Ballerstaller
 * eMail			: Chris.Balla@web.de
 * Last modified	: 19 March 2003
 * License			: Released under GPL General Public License
 * 
 * .NET Framework	: Version 1.0
 * 
 * Description		: IP Address / Port / Subnet Mask submission form
 */


using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;

using System.Windows.Forms;


namespace LiquidForms.FrmCommon
{
	enum ShowGUI : int
	{
		IP,						// IP address can be entered
		IP_Port,				// IP address and port can be entered
		IP_Port_Subnet,			// IP address and port and subnet can be entered
		IP_Port_Subnet_Local	// IP address and port and subnet can be entered
								// Local network controller settings are displayed
	}

	public class FrmIPSubnet : LiquidForms.FrmBase.FrmDialog
	{
		private System.Windows.Forms.Label lblLine3;
		private System.Windows.Forms.Label lblLine4;
		private System.Windows.Forms.Label lblLine1;
		private System.Windows.Forms.Label lblLine2;
		private System.Windows.Forms.Label lblLocalWarning;
		private System.Windows.Forms.ComboBox cbxLocal;
		private System.Windows.Forms.Label lblLocal;
		private System.Windows.Forms.Label lblStatus;
		private System.Windows.Forms.Label lblSubnet;
		private System.Windows.Forms.GroupBox gbxIP;
		private System.Windows.Forms.Panel pnlIP;
		private System.Windows.Forms.Label lblIPDot3;
		private System.Windows.Forms.Label lblIPDot2;
		private System.Windows.Forms.TextBox txtIP3;
		private System.Windows.Forms.TextBox txtIP2;
		private System.Windows.Forms.Label lblIPDot1;
		private System.Windows.Forms.TextBox txtIP1;
		private System.Windows.Forms.TextBox txtIP4;
		private System.Windows.Forms.Label lblIPDot4;
		private System.Windows.Forms.TextBox txtPort;
		private System.Windows.Forms.Label lblIP;
		private System.Windows.Forms.GroupBox gbxSubnet;
		private System.Windows.Forms.Panel pnlSubnet;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox txtSub3;
		private System.Windows.Forms.TextBox txtSub2;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox txtSub1;
		private System.Windows.Forms.TextBox txtSub4;
		private System.ComponentModel.IContainer components = null;

		private string lastKnownGoodIP		= "0";
		private string lastKnownGoodSub		= "0";
		private string lastKnownGoodPort	= "0";

		private int IPMin;
		private int IPMax;
		private System.Windows.Forms.Label lblMessage;
		private System.Windows.Forms.Panel pnlTop;
		private System.Windows.Forms.Panel pnlContent;

		private int intShowType;

		/// <summary>
		/// Constructor: IP address and port and subnet can be entered
		///				 Local network controller settings are displayed
		/// </summary>
		/// <param name="title">Title for form</param>
		/// <param name="txtBtnOK">Text for Button OK</param>
		/// <param name="txtBtnCancel">Text for Button Cancel</param>
		/// <param name="IP">String with IP Address. Format: 192.168.0.1</param>
		/// <param name="Port">String with Portnumber. Format: 55521</param>
		/// <param name="Subnet">String with Subnet Mask. Format: 255.255.255.0</param>
		/// <param name="txtWarningLocalSubnet">Text for Label (Checks status of local network devices)</param>
		public FrmIPSubnet(string title, string message, string txtBtnOK, string txtBtnCancel, string IP, string Port, string Subnet, string txtWarningLocalSubnet)
		{
			InitializeComponent();
			InitializePreconditions();
			InitializeLanguage();

			this.Text				= title;
			this.lblMessage.Text	= message;
			this.btnOK.Text			= txtBtnOK;
			this.btnCancel.Text		= txtBtnCancel;

			this.IPAddress			= IP;
			this.Port				= Port;
			this.SubnetMask			= Subnet;

			int Major=System.Environment.OSVersion.Version.Major;
			int Minor=System.Environment.OSVersion.Version.Minor;
			int Build=System.Environment.OSVersion.Version.Build;

			bool showLocalInfos = true;
			string strOS		= "";

			if(Major==4 && Minor==0) // Win95
			{
				showLocalInfos = false;
				strOS = "Win95";
			}
			else if(Major==4 && Minor==10) // Win98
			{
				showLocalInfos = false;
				strOS = "Win98";
			}
			else if(Major==4 && Minor==10 && Build==1998) // Win98SE
			{
				showLocalInfos = false;
				strOS = "Win98SE";
			}
			else if(Major==4 && Minor==90) // WinME
			{
				showLocalInfos = false;
				strOS = "WinME";
			}

			if(showLocalInfos==true)
			{
				// OS is supporting 'Win32_NetworkAdapterConfiguration'
				ShowType = (int)ShowGUI.IP_Port_Subnet_Local;
				lblLocalWarning.Text=txtWarningLocalSubnet;

				// Show Network adapter configuration
				ReportIP();
			}
			else
			{
				// OS is not supporting 'Win32_NetworkAdapterConfiguration'
				ShowType = (int)ShowGUI.IP_Port_Subnet;
				lblLocalWarning.Text = "Can't read system's network configuration because you're running "+strOS+".";
			}
		}

		/// <summary>
		/// Constructor: IP address and port and subnet can be entered
		/// </summary>
		/// <param name="title">Title for form</param>
		/// <param name="txtBtnOK">Text for Button OK</param>
		/// <param name="txtBtnCancel">Text for Button Cancel</param>
		/// <param name="IP">String with IP Address. Format: 192.168.0.1</param>
		/// <param name="Port">String with Portnumber. Format: 55521</param>
		/// <param name="Subnet">String with Subnet Mask. Format: 255.255.255.0</param>
		public FrmIPSubnet(string title, string message, string txtBtnOK, string txtBtnCancel, string IP, string Port, string Subnet)
		{
			InitializeComponent();
			InitializePreconditions();
			InitializeLanguage();
			this.Text				= title;
			this.lblMessage.Text	= message;
			this.btnOK.Text			= txtBtnOK;
			this.btnCancel.Text		= txtBtnCancel;

			this.IPAddress			= IP;
			this.Port				= Port;
			this.SubnetMask			= Subnet;

			ShowType = (int)ShowGUI.IP_Port_Subnet;
			lblLocalWarning.Text	= ""; // No text, it's visible because maybe win98 error is displayed
		}

		/// <summary>
		/// Constructor: IP address and port can be entered
		/// </summary>
		/// <param name="title">Title for form</param>
		/// <param name="txtBtnOK">Text for Button OK</param>
		/// <param name="txtBtnCancel">Text for Button Cancel</param>
		/// <param name="IP">String with IP Address. Format: 192.168.0.1</param>
		/// <param name="Port">String with Portnumber. Format: 55521</param>
		public FrmIPSubnet(string title, string message, string txtBtnOK, string txtBtnCancel, string IP, string Port)
		{
			InitializeComponent();
			InitializePreconditions();
			InitializeLanguage();
			this.Text				= title;
			this.lblMessage.Text	= message;
			this.btnOK.Text			= txtBtnOK;
			this.btnCancel.Text		= txtBtnCancel;

			this.IPAddress			= IP;
			this.Port				= Port;

			ShowType = (int)ShowGUI.IP_Port;
		}

		/// <summary>
		/// Constructor: IP address can be entered
		/// </summary>
		/// <param name="title">Title for form</param>
		/// <param name="txtBtnOK">Text for Button OK</param>
		/// <param name="txtBtnCancel">Text for Button Cancel</param>
		/// <param name="IP">String with IP Address. Format: 192.168.0.1</param>
		public FrmIPSubnet(string title, string message, string txtBtnOK, string txtBtnCancel, string IP)
		{
			InitializeComponent();
			InitializePreconditions();
			InitializeLanguage();
			this.Text				= title;
			this.lblMessage.Text	= message;
			this.btnOK.Text			= txtBtnOK;
			this.btnCancel.Text		= txtBtnCancel;

			this.IPAddress			= IP;

			ShowType = (int)ShowGUI.IP;
		}

		/// <summary>
		/// Fill input fields with standard values
		/// Called by constructor 
		/// </summary>
		private void InitializePreconditions()
		{
			txtIP1.Text		= "168";
			txtIP2.Text		= "192";
			txtIP3.Text		= "0";
			txtIP4.Text		= "1";

			txtPort.Text	= "1";

			txtSub1.Text	= "255";
			txtSub2.Text	= "255";
			txtSub3.Text	= "255";
			txtSub4.Text	= "0";
		}

		/// <summary>
		/// Initializes language for GUI components
		/// </summary>
		public void InitializeLanguage()
		{
			this.lblIP.Text			= "IP:";
			this.lblSubnet.Text		= "Subnet:";
			this.lblLocal.Text		= "Local:";
		}

		/// <summary>
		/// Reads computers network configuration and adds
		/// - Adapter name
		/// - IP Addresses
		/// - Subnet Masks
		/// to a listbox.
		/// </summary>
		private void ReportIP()
		{
			try
			{
				ArrayList arrIPInfos = GD.NetworkMngr.Network.ReportIP();
				foreach(ArrayList arrIPInfo in arrIPInfos)				
				{
					// Formats and adds adapter name
					cbxLocal.Items.Add("Adapter: "+arrIPInfo[0].ToString().Split(']')[1]);

					// Formats and adds ip address
					string[] addresses	= (string[])arrIPInfo[3];
					for(int j=0; j<addresses.Length; j++)
						cbxLocal.Items.Add(" -> IP:          "+addresses[j]);

					// Formats and adds subnet address
					string[] subnets	= (string[])arrIPInfo[4];
					for(int j=0; j<subnets.Length; j++)
						cbxLocal.Items.Add(" -> Subnet:  "+subnets[j]);
				}

				// No network adapter found
				if(cbxLocal.Items.Count==0)
					cbxLocal.Items.Add("No Network adapter available.");
			}
			catch(Exception e)
			{
				// An error occured
				cbxLocal.Items.Add("Error: "+e.Message);
			}
		}

		/// <summary>
		/// Gets or sets the view of the current form.
		/// The showed components are depending on the invoked constructor
		/// </summary>
		private int ShowType
		{
			get {return intShowType;}
			set 
			{
				if(value==(int)ShowGUI.IP) // IP address can be entered
				{
					lblSubnet.Visible		= false;
					gbxSubnet.Visible		= false;
					lblStatus.Visible		= false;
					lblIPDot4.Visible		= false;
					txtPort.Visible			= false;
					lblLocal.Visible		= false;
					cbxLocal.Visible		= false;

					this.pnlIP.Size			= new System.Drawing.Size(180, 23);
					this.gbxIP.Size			= new System.Drawing.Size(196, 40);

					lblLine1.Visible		= false;
					lblLine2.Visible		= false;
					lblLine3.Visible		= false;
					lblLine4.Visible		= false;

					this.Size				= new System.Drawing.Size(406, 202);
				}

				else if(value==(int)ShowGUI.IP_Port) // IP address and port can be entered
				{
					lblSubnet.Visible		= false;
					gbxSubnet.Visible		= false;
					lblStatus.Visible		= false;
					lblLocal.Visible		= false;
					cbxLocal.Visible		= false;
					lblLocalWarning.Visible = false;

					lblLine1.Visible		= false;
					lblLine2.Visible		= false;
					lblLine3.Visible		= false;
					lblLine4.Visible		= false;

					this.Size				= new System.Drawing.Size(466, 202);
				}

				else if(value==(int)ShowGUI.IP_Port_Subnet) // IP address and port and subnet can be entered
				{
					lblLocal.Visible		= false;
					cbxLocal.Visible		= false;

					this.Size				= new System.Drawing.Size(466, 262);
				}

				else	// IP address and port and subnet can be entered
					// Local network controller settings are displayed
				{
				}

				intShowType = value;
			}
		}

		/// <summary>
		/// Gets or sets the IP Address
		/// Get example result: 192.168.0.1
		/// Set example: 192.168.0.1
		/// </summary>
		public string IPAddress
		{
			get {return txtIP1.Text+"."+txtIP2.Text+"."+txtIP3.Text+"."+txtIP4.Text;}
			set
			{
				try
				{
					txtIP4.Text=value.Split('.')[3];
					txtIP3.Text=value.Split('.')[2];
					txtIP2.Text=value.Split('.')[1];
					txtIP1.Text=value.Split('.')[0];
				}
				catch(Exception e)
				{
					GenError("Could not initialize IP Address.\r\n"+e.Message);
				}
			}
		}

		/// <summary>
		/// Gets or sets the IP Port
		/// </summary>
		public string Port
		{
			get {return txtPort.Text;}
			set
			{
				try
				{
					txtPort.Text = value;
				}
				catch(Exception e)
				{
					GenError("Could not initalize Port Address.\r\n"+e.Message);
				}
			}
		}

		/// <summary>
		/// Gets or sets the Subnet mask
		/// Get example result: 255.255.255.0
		/// Set example: 255.255.255.0
		/// </summary>
		public string SubnetMask
		{
			get {return txtSub1.Text+"."+txtSub2.Text+"."+txtSub3.Text+"."+txtSub4.Text;}
			set
			{
				try
				{
					txtSub1.Text=value.Split('.')[0];
					txtSub2.Text=value.Split('.')[1];
					txtSub3.Text=value.Split('.')[2];
					txtSub4.Text=value.Split('.')[3];
				}
				catch(Exception e)
				{
					GenError("Could not initialize Subnet Mask.\r\n"+e.Message);
				}
			}
		}

		/// <summary>
		/// User pressed a key in either ip, port or subnet input boxes
		/// Only numbers (and backspace / delete / tab / arrow keys) are accepted!
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txt_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			// Checks for numbers
			if(e.KeyChar<'0' || e.KeyChar>'9')
				e.Handled = true;

			// Checks for backspace
			if(e.KeyChar==8)
				e.Handled = false;
		}

		/// <summary>
		/// Text in port-textfield has changed
		/// Checks, if port is in the allowed port-range
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtPort_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				// Check, if port is in the allowed range
				if ((Int32.Parse(txtPort.Text)>0)&&(Int32.Parse(txtPort.Text)<=65535))
				{
					lastKnownGoodPort=txtPort.Text;
				}
				else
				{
					txtPort.Text = lastKnownGoodPort;
					txtPort.SelectionStart=0;

					GenError("The entered value is too big / small.");
				}
			}
			catch(Exception)
			{
				GenError("The entered value is not a number.");
			}
		}

		/// <summary>
		/// Part of ip address has changed
		/// Checks, if the ip address is in the allowed range
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtIP_TextChanged(object sender, System.EventArgs e)
		{
			TextBox tb = (TextBox)sender;

			if (tb.Text == "")
			{
				tb.Text = "0";
				tb.SelectionStart = 0;
				tb.SelectionLength = 1;
			}

			try
			{
				switch(tb.Name)
				{
					case "txtIP1":
					{
						IPMin=1;	// minimum value
						IPMax=223;	// maximum value
						
						// Checks, if the entered ip address is fitting to the entered subnet mask.
						CheckValid();

						break;
					}
					default:
					{
						IPMin=0;	// minumum value
						IPMax=255;	// maximum value
						break;
					}
				}

				// this part of the ip address is in the allowed range
				if(Int32.Parse(tb.Text)<=IPMax && Int32.Parse(tb.Text)>=IPMin)
				{
					lastKnownGoodIP = tb.Text;
				}
				else // if not... restore last value
				{
					int ss = tb.SelectionStart;
					tb.Text = lastKnownGoodIP;
					tb.SelectionStart = ss-1;
				}
			}
			catch(Exception)
			{
				tb.Text = lastKnownGoodIP;
			}
		}

		/// <summary>
		/// Checks, if the entered ip address is fitting to the entered subnet mask.
		/// If valid then statuscolor = green, if not statuscolor = red
		/// See FrmIPSubnet.txt comment file for details (Section: Validation)
		/// </summary>
		private void CheckValid()
		{
			if((Int32.Parse(txtIP1.Text)>=0 && Int32.Parse(txtIP1.Text)<=127) && txtSub1.Text=="255")
			{
				lblStatus.BackColor = System.Drawing.Color.Green;
				lblStatus.Text		= "=";
			}
			else if((Int32.Parse(txtIP1.Text)>=128 && Int32.Parse(txtIP1.Text)<=191) && (txtSub1.Text=="255" && txtSub2.Text=="255"))
			{
				lblStatus.BackColor = System.Drawing.Color.Green;
				lblStatus.Text		= "=";
			}
			else if((Int32.Parse(txtIP1.Text)>=192 && Int32.Parse(txtIP1.Text)<=255) && (txtSub1.Text=="255" && txtSub2.Text=="255" && txtSub3.Text=="255"))
			{
				lblStatus.BackColor = System.Drawing.Color.Green;
				lblStatus.Text		= "=";
			}
			else
			{
				lblStatus.BackColor = System.Drawing.Color.Red;
				lblStatus.Text		= "X";
			}
		}

		/// <summary>
		/// Part of subnet mask has changed
		/// Checks, of the subnet mask is in the allowed range
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtSub_TextChanged(object sender, System.EventArgs e)
		{
			TextBox tb = (TextBox)sender;

			IPMin = 0;
			IPMax = 255;

			if (tb.Text == "")
			{
				tb.Text = "0";
				tb.SelectionStart = 0;
				tb.SelectionLength = 1;
			}

			try
			{
				// this part of the subnet mask is in the allowed range
				if(Int32.Parse(tb.Text)<=IPMax && Int32.Parse(tb.Text)>=IPMin)
				{
					lastKnownGoodSub = tb.Text;
				}
				else // if not... restore last value
				{
					int ss = tb.SelectionStart;
					tb.Text = lastKnownGoodSub;
					tb.SelectionStart = ss-1;
				}
			}

			catch(Exception)
			{
				tb.Text = lastKnownGoodSub;
			}

			// Checks, if the entered ip address is fitting to the entered subnet mask.
			CheckValid();
		}

		/// <summary>
		/// Checks the conditions for block 1
		/// See FrmIPSubnet.txt comment file for details
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtSub1_Leave(object sender, System.EventArgs e)
		{
			// Condition No. 4
			if(txtSub1.Text=="0")
			{
				txtSub1.Select();
				GenError("0 not valid in first block.");
			}

			// Condition No. 3
			if(txtSub1.Text!="255")
			{
				txtSub2.Text="0";
				txtSub3.Text="0";
				txtSub4.Text="0";
			}
		}

		/// <summary>
		/// Checks the conditions for block 2
		/// See FrmIPSubnet.txt comment file for details
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtSub2_Leave(object sender, System.EventArgs e)
		{
			// Condition No. 2
			if(txtSub2.Text!="0")
			{
				txtSub1.Text="255";
			}

			// Condition No. 3
			if(txtSub2.Text!="255")
			{
				txtSub3.Text="0";
				txtSub4.Text="0";
			}

		}

		/// <summary>
		/// Checks the conditions for block 3
		/// See FrmIPSubnet.txt comment file for details
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtSub3_Leave(object sender, System.EventArgs e)
		{
			// Condition No. 2
			if(txtSub3.Text!="0")
			{
				txtSub1.Text="255";
				txtSub2.Text="255";
			}

			// Condition No. 3
			if(txtSub3.Text!="255")
			{
				txtSub4.Text="0";
			}
		
		}

		/// <summary>
		/// Checks the conditions for block 4
		/// See FrmIPSubnet.txt comment file for details
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtSub4_Leave(object sender, System.EventArgs e)
		{
			// Condition No. 4
			if(txtSub4.Text=="254" | txtSub4.Text=="255")
			{
				txtSub4.Select();
				GenError("254, 255 im letzten Feld ned erlaubt");
			}

			// Condition No. 2
			if(txtSub4.Text!="0")
			{
				txtSub1.Text="255";
				txtSub2.Text="255";
				txtSub3.Text="255";
			}
			
		}

		/// <summary>
		/// Checks if entered number for block n of the subnet mask is valid.
		/// If yes, the specific textbox event is called
		/// if not, error message is displayed
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void txtSub_Leave(object sender, System.EventArgs e)
		{
			TextBox tb = (TextBox)sender;

			// See FrmIPSubnet.txt comment file for details
			// Condition No. 1
			if(tb.Text=="0" || tb.Text=="128" || tb.Text=="192" || tb.Text=="224" || tb.Text=="240" ||
				tb.Text=="248" || tb.Text=="252" || tb.Text=="254" || tb.Text=="255")
			{
			}
			else
			{
				GenError("Not possible. Value must be either 0, 128, 192, 224, 240, 248, 252, 254, 255.");
				tb.Select();
			}

			if(tb.Name=="txtSub1")
				txtSub1_Leave(sender, e);
			else if(tb.Name=="txtSub2")
				txtSub2_Leave(sender, e);
			else if(tb.Name=="txtSub3")
				txtSub3_Leave(sender, e);
			else if(tb.Name=="txtSub4")
				txtSub4_Leave(sender, e);
		}

		/// <summary>
		/// Generates an error message
		/// </summary>
		/// <param name="errorMessage"></param>
		private void GenError(string errorMessage)
		{
			MessageBox.Show(this, errorMessage, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
		}

		protected override void btnOK_Click(object sender, EventArgs e)
		{
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region 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.lblLine3 = new System.Windows.Forms.Label();
			this.lblLine4 = new System.Windows.Forms.Label();
			this.lblLine1 = new System.Windows.Forms.Label();
			this.lblLine2 = new System.Windows.Forms.Label();
			this.lblLocalWarning = new System.Windows.Forms.Label();
			this.cbxLocal = new System.Windows.Forms.ComboBox();
			this.lblLocal = new System.Windows.Forms.Label();
			this.lblStatus = new System.Windows.Forms.Label();
			this.lblSubnet = new System.Windows.Forms.Label();
			this.gbxIP = new System.Windows.Forms.GroupBox();
			this.pnlIP = new System.Windows.Forms.Panel();
			this.lblIPDot3 = new System.Windows.Forms.Label();
			this.lblIPDot2 = new System.Windows.Forms.Label();
			this.txtIP3 = new System.Windows.Forms.TextBox();
			this.txtIP2 = new System.Windows.Forms.TextBox();
			this.lblIPDot1 = new System.Windows.Forms.Label();
			this.txtIP1 = new System.Windows.Forms.TextBox();
			this.txtIP4 = new System.Windows.Forms.TextBox();
			this.lblIPDot4 = new System.Windows.Forms.Label();
			this.txtPort = new System.Windows.Forms.TextBox();
			this.lblIP = new System.Windows.Forms.Label();
			this.gbxSubnet = new System.Windows.Forms.GroupBox();
			this.pnlSubnet = new System.Windows.Forms.Panel();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.txtSub3 = new System.Windows.Forms.TextBox();
			this.txtSub2 = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.txtSub1 = new System.Windows.Forms.TextBox();
			this.txtSub4 = new System.Windows.Forms.TextBox();
			this.lblMessage = new System.Windows.Forms.Label();
			this.pnlTop = new System.Windows.Forms.Panel();
			this.pnlContent = new System.Windows.Forms.Panel();
			this.gbxIP.SuspendLayout();
			this.pnlIP.SuspendLayout();
			this.gbxSubnet.SuspendLayout();
			this.pnlSubnet.SuspendLayout();
			this.pnlTop.SuspendLayout();
			this.pnlContent.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnOK
			// 
			this.btnOK.Visible = true;
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(274, 24);
			this.btnCancel.Visible = true;
			// 
			// lblLine3
			// 
			this.lblLine3.BackColor = System.Drawing.Color.Black;
			this.lblLine3.Location = new System.Drawing.Point(400, 56);
			this.lblLine3.Name = "lblLine3";
			this.lblLine3.Size = new System.Drawing.Size(1, 16);
			this.lblLine3.TabIndex = 38;
			// 
			// lblLine4
			// 
			this.lblLine4.BackColor = System.Drawing.Color.Black;
			this.lblLine4.Location = new System.Drawing.Point(328, 72);
			this.lblLine4.Name = "lblLine4";
			this.lblLine4.Size = new System.Drawing.Size(72, 1);
			this.lblLine4.TabIndex = 37;
			// 
			// lblLine1
			// 
			this.lblLine1.BackColor = System.Drawing.Color.Black;
			this.lblLine1.Location = new System.Drawing.Point(376, 24);
			this.lblLine1.Name = "lblLine1";
			this.lblLine1.Size = new System.Drawing.Size(24, 1);
			this.lblLine1.TabIndex = 36;
			// 
			// lblLine2
			// 
			this.lblLine2.BackColor = System.Drawing.Color.Black;
			this.lblLine2.Location = new System.Drawing.Point(400, 24);
			this.lblLine2.Name = "lblLine2";
			this.lblLine2.Size = new System.Drawing.Size(1, 16);
			this.lblLine2.TabIndex = 35;
			// 
			// lblLocalWarning
			// 
			this.lblLocalWarning.Location = new System.Drawing.Point(48, 104);
			this.lblLocalWarning.Name = "lblLocalWarning";
			this.lblLocalWarning.Size = new System.Drawing.Size(360, 32);
			this.lblLocalWarning.TabIndex = 34;
			this.lblLocalWarning.Text = "lblLocalWarning";
			// 
			// cbxLocal
			// 
			this.cbxLocal.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cbxLocal.Location = new System.Drawing.Point(120, 144);
			this.cbxLocal.Name = "cbxLocal";
			this.cbxLocal.Size = new System.Drawing.Size(288, 21);
			this.cbxLocal.TabIndex = 33;
			// 
			// lblLocal
			// 
			this.lblLocal.Location = new System.Drawing.Point(48, 144);
			this.lblLocal.Name = "lblLocal";
			this.lblLocal.Size = new System.Drawing.Size(72, 23);
			this.lblLocal.TabIndex = 32;
			this.lblLocal.Text = "lblLocal";
			this.lblLocal.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblStatus
			// 
			this.lblStatus.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.lblStatus.ForeColor = System.Drawing.Color.White;
			this.lblStatus.Location = new System.Drawing.Point(392, 40);
			this.lblStatus.Name = "lblStatus";
			this.lblStatus.Size = new System.Drawing.Size(16, 16);
			this.lblStatus.TabIndex = 31;
			this.lblStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lblSubnet
			// 
			this.lblSubnet.Location = new System.Drawing.Point(48, 64);
			this.lblSubnet.Name = "lblSubnet";
			this.lblSubnet.Size = new System.Drawing.Size(72, 23);
			this.lblSubnet.TabIndex = 30;
			this.lblSubnet.Text = "lblSubnet";
			this.lblSubnet.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// gbxIP
			// 
			this.gbxIP.Controls.AddRange(new System.Windows.Forms.Control[] {
																				this.pnlIP});
			this.gbxIP.Location = new System.Drawing.Point(120, 8);
			this.gbxIP.Name = "gbxIP";
			this.gbxIP.Size = new System.Drawing.Size(256, 40);
			this.gbxIP.TabIndex = 27;
			this.gbxIP.TabStop = false;
			// 
			// pnlIP
			// 
			this.pnlIP.BackColor = System.Drawing.Color.White;
			this.pnlIP.Controls.AddRange(new System.Windows.Forms.Control[] {
																				this.lblIPDot3,
																				this.lblIPDot2,
																				this.txtIP3,
																				this.txtIP2,
																				this.lblIPDot1,
																				this.txtIP1,
																				this.txtIP4,
																				this.lblIPDot4,
																				this.txtPort});
			this.pnlIP.Location = new System.Drawing.Point(8, 11);
			this.pnlIP.Name = "pnlIP";
			this.pnlIP.Size = new System.Drawing.Size(240, 23);
			this.pnlIP.TabIndex = 15;
			// 
			// lblIPDot3
			// 
			this.lblIPDot3.BackColor = System.Drawing.Color.White;
			this.lblIPDot3.Location = new System.Drawing.Point(136, 8);
			this.lblIPDot3.Name = "lblIPDot3";
			this.lblIPDot3.Size = new System.Drawing.Size(8, 11);
			this.lblIPDot3.TabIndex = 8;
			this.lblIPDot3.Text = ".";
			this.lblIPDot3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lblIPDot2
			// 
			this.lblIPDot2.BackColor = System.Drawing.Color.White;
			this.lblIPDot2.Location = new System.Drawing.Point(96, 8);
			this.lblIPDot2.Name = "lblIPDot2";
			this.lblIPDot2.Size = new System.Drawing.Size(8, 11);
			this.lblIPDot2.TabIndex = 4;
			this.lblIPDot2.Text = ".";
			this.lblIPDot2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// txtIP3
			// 
			this.txtIP3.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtIP3.Location = new System.Drawing.Point(104, 8);
			this.txtIP3.MaxLength = 3;
			this.txtIP3.Name = "txtIP3";
			this.txtIP3.Size = new System.Drawing.Size(32, 13);
			this.txtIP3.TabIndex = 3;
			this.txtIP3.Text = "txtIP3";
			this.txtIP3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtIP3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtIP3.TextChanged += new System.EventHandler(this.txtIP_TextChanged);
			// 
			// txtIP2
			// 
			this.txtIP2.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtIP2.Location = new System.Drawing.Point(64, 8);
			this.txtIP2.MaxLength = 3;
			this.txtIP2.Name = "txtIP2";
			this.txtIP2.Size = new System.Drawing.Size(32, 13);
			this.txtIP2.TabIndex = 2;
			this.txtIP2.Text = "txtIP2";
			this.txtIP2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtIP2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtIP2.TextChanged += new System.EventHandler(this.txtIP_TextChanged);
			// 
			// lblIPDot1
			// 
			this.lblIPDot1.BackColor = System.Drawing.Color.White;
			this.lblIPDot1.Location = new System.Drawing.Point(56, 8);
			this.lblIPDot1.Name = "lblIPDot1";
			this.lblIPDot1.Size = new System.Drawing.Size(8, 11);
			this.lblIPDot1.TabIndex = 2;
			this.lblIPDot1.Text = ".";
			this.lblIPDot1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// txtIP1
			// 
			this.txtIP1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtIP1.Location = new System.Drawing.Point(24, 8);
			this.txtIP1.MaxLength = 3;
			this.txtIP1.Name = "txtIP1";
			this.txtIP1.Size = new System.Drawing.Size(32, 13);
			this.txtIP1.TabIndex = 1;
			this.txtIP1.Text = "txtIP1";
			this.txtIP1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtIP1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtIP1.TextChanged += new System.EventHandler(this.txtIP_TextChanged);
			// 
			// txtIP4
			// 
			this.txtIP4.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtIP4.Location = new System.Drawing.Point(144, 8);
			this.txtIP4.MaxLength = 3;
			this.txtIP4.Name = "txtIP4";
			this.txtIP4.Size = new System.Drawing.Size(32, 13);
			this.txtIP4.TabIndex = 4;
			this.txtIP4.Text = "txtIP4";
			this.txtIP4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtIP4.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtIP4.TextChanged += new System.EventHandler(this.txtIP_TextChanged);
			// 
			// lblIPDot4
			// 
			this.lblIPDot4.Location = new System.Drawing.Point(176, 8);
			this.lblIPDot4.Name = "lblIPDot4";
			this.lblIPDot4.Size = new System.Drawing.Size(8, 14);
			this.lblIPDot4.TabIndex = 16;
			this.lblIPDot4.Text = ":";
			// 
			// txtPort
			// 
			this.txtPort.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtPort.Location = new System.Drawing.Point(184, 8);
			this.txtPort.MaxLength = 5;
			this.txtPort.Name = "txtPort";
			this.txtPort.Size = new System.Drawing.Size(40, 13);
			this.txtPort.TabIndex = 16;
			this.txtPort.Text = "txtPort";
			this.txtPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtPort.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtPort.TextChanged += new System.EventHandler(this.txtPort_TextChanged);
			// 
			// lblIP
			// 
			this.lblIP.Location = new System.Drawing.Point(48, 16);
			this.lblIP.Name = "lblIP";
			this.lblIP.Size = new System.Drawing.Size(72, 24);
			this.lblIP.TabIndex = 29;
			this.lblIP.Text = "lblIP";
			this.lblIP.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// gbxSubnet
			// 
			this.gbxSubnet.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.pnlSubnet});
			this.gbxSubnet.Location = new System.Drawing.Point(120, 56);
			this.gbxSubnet.Name = "gbxSubnet";
			this.gbxSubnet.Size = new System.Drawing.Size(208, 38);
			this.gbxSubnet.TabIndex = 28;
			this.gbxSubnet.TabStop = false;
			// 
			// pnlSubnet
			// 
			this.pnlSubnet.BackColor = System.Drawing.Color.White;
			this.pnlSubnet.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.label5,
																					this.label6,
																					this.txtSub3,
																					this.txtSub2,
																					this.label7,
																					this.txtSub1,
																					this.txtSub4});
			this.pnlSubnet.Location = new System.Drawing.Point(8, 11);
			this.pnlSubnet.Name = "pnlSubnet";
			this.pnlSubnet.Size = new System.Drawing.Size(192, 22);
			this.pnlSubnet.TabIndex = 18;
			// 
			// label5
			// 
			this.label5.BackColor = System.Drawing.Color.White;
			this.label5.Location = new System.Drawing.Point(136, 8);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(8, 10);
			this.label5.TabIndex = 8;
			this.label5.Text = ".";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label6
			// 
			this.label6.BackColor = System.Drawing.Color.White;
			this.label6.Location = new System.Drawing.Point(96, 8);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(8, 10);
			this.label6.TabIndex = 4;
			this.label6.Text = ".";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// txtSub3
			// 
			this.txtSub3.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtSub3.Location = new System.Drawing.Point(104, 8);
			this.txtSub3.MaxLength = 3;
			this.txtSub3.Name = "txtSub3";
			this.txtSub3.Size = new System.Drawing.Size(32, 13);
			this.txtSub3.TabIndex = 3;
			this.txtSub3.Text = "txtSub3";
			this.txtSub3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtSub3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtSub3.TextChanged += new System.EventHandler(this.txtSub_TextChanged);
			this.txtSub3.Leave += new System.EventHandler(this.txtSub_Leave);
			// 
			// txtSub2
			// 
			this.txtSub2.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtSub2.Location = new System.Drawing.Point(64, 8);
			this.txtSub2.MaxLength = 3;
			this.txtSub2.Name = "txtSub2";
			this.txtSub2.Size = new System.Drawing.Size(32, 13);
			this.txtSub2.TabIndex = 2;
			this.txtSub2.Text = "txtSub2";
			this.txtSub2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtSub2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtSub2.TextChanged += new System.EventHandler(this.txtSub_TextChanged);
			this.txtSub2.Leave += new System.EventHandler(this.txtSub_Leave);
			// 
			// label7
			// 
			this.label7.BackColor = System.Drawing.Color.White;
			this.label7.Location = new System.Drawing.Point(56, 8);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(8, 10);
			this.label7.TabIndex = 2;
			this.label7.Text = ".";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// txtSub1
			// 
			this.txtSub1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtSub1.Location = new System.Drawing.Point(24, 8);
			this.txtSub1.MaxLength = 3;
			this.txtSub1.Name = "txtSub1";
			this.txtSub1.Size = new System.Drawing.Size(32, 13);
			this.txtSub1.TabIndex = 1;
			this.txtSub1.Text = "txtSub1";
			this.txtSub1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtSub1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtSub1.TextChanged += new System.EventHandler(this.txtSub_TextChanged);
			this.txtSub1.Leave += new System.EventHandler(this.txtSub_Leave);
			// 
			// txtSub4
			// 
			this.txtSub4.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.txtSub4.Location = new System.Drawing.Point(144, 8);
			this.txtSub4.MaxLength = 3;
			this.txtSub4.Name = "txtSub4";
			this.txtSub4.Size = new System.Drawing.Size(32, 13);
			this.txtSub4.TabIndex = 4;
			this.txtSub4.Text = "txtSub4";
			this.txtSub4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.txtSub4.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_KeyPress);
			this.txtSub4.TextChanged += new System.EventHandler(this.txtSub_TextChanged);
			this.txtSub4.Leave += new System.EventHandler(this.txtSub_Leave);
			// 
			// lblMessage
			// 
			this.lblMessage.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblMessage.Location = new System.Drawing.Point(48, 12);
			this.lblMessage.Name = "lblMessage";
			this.lblMessage.Size = new System.Drawing.Size(368, 28);
			this.lblMessage.TabIndex = 39;
			this.lblMessage.Text = "lblMessage";
			// 
			// pnlTop
			// 
			this.pnlTop.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.lblMessage});
			this.pnlTop.Dock = System.Windows.Forms.DockStyle.Top;
			this.pnlTop.Name = "pnlTop";
			this.pnlTop.Size = new System.Drawing.Size(458, 48);
			this.pnlTop.TabIndex = 40;
			// 
			// pnlContent
			// 
			this.pnlContent.Controls.AddRange(new System.Windows.Forms.Control[] {
																					 this.lblLine3,
																					 this.lblIP,
																					 this.gbxSubnet,
																					 this.lblLine2,
																					 this.lblLine1,
																					 this.lblLine4,
																					 this.lblSubnet,
																					 this.lblStatus,
																					 this.gbxIP,
																					 this.lblLocalWarning,
																					 this.cbxLocal,
																					 this.lblLocal});
			this.pnlContent.Dock = System.Windows.Forms.DockStyle.Fill;
			this.pnlContent.Location = new System.Drawing.Point(0, 48);
			this.pnlContent.Name = "pnlContent";
			this.pnlContent.Size = new System.Drawing.Size(458, 245);
			this.pnlContent.TabIndex = 41;
			// 
			// FrmIPSubnet
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(458, 293);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.pnlContent,
																		  this.pnlTop});
			this.Name = "FrmIPSubnet";
			this.gbxIP.ResumeLayout(false);
			this.pnlIP.ResumeLayout(false);
			this.gbxSubnet.ResumeLayout(false);
			this.pnlSubnet.ResumeLayout(false);
			this.pnlTop.ResumeLayout(false);
			this.pnlContent.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion


	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
Experience:
- Java
- C#
- XML, XSL, PHP, ASP, ASP.NET
- Server administration

- ASM, Visual Basic (poor)
- Linux (poor)

If you have any offers, questions, or project ideas please feel free to contact me.

If you experience any bugs in my software, please report them.

Thank you.

Comments and Discussions