ArcObjects Library Reference  

ZipCodeDlg

About the RSS weather layer Sample

[C#]

ZipCodeDlg.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace RSSWeatherLayer
{
	/// <summary>
	/// Gets the input zipCode from the user
	/// </summary>
	public class ZipCodeDlg : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtZipCode;
		private System.Windows.Forms.Label lblZipCode;
		private System.Windows.Forms.CheckBox chkZoomTo;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ZipCodeDlg()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <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 Windows Form 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.txtZipCode = new System.Windows.Forms.TextBox();
			this.lblZipCode = new System.Windows.Forms.Label();
			this.chkZoomTo = new System.Windows.Forms.CheckBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// txtZipCode
			// 
			this.txtZipCode.Location = new System.Drawing.Point(64, 24);
			this.txtZipCode.Name = "txtZipCode";
			this.txtZipCode.TabIndex = 0;
			this.txtZipCode.Text = "";
			// 
			// lblZipCode
			// 
			this.lblZipCode.Location = new System.Drawing.Point(8, 24);
			this.lblZipCode.Name = "lblZipCode";
			this.lblZipCode.Size = new System.Drawing.Size(48, 16);
			this.lblZipCode.TabIndex = 1;
			this.lblZipCode.Text = "ZipCode:";
			// 
			// chkZoomTo
			// 
			this.chkZoomTo.Location = new System.Drawing.Point(8, 56);
			this.chkZoomTo.Name = "chkZoomTo";
			this.chkZoomTo.TabIndex = 2;
			this.chkZoomTo.Text = "Zoom to item";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.chkZoomTo);
			this.groupBox1.Controls.Add(this.txtZipCode);
			this.groupBox1.Controls.Add(this.lblZipCode);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(176, 88);
			this.groupBox1.TabIndex = 3;
			this.groupBox1.TabStop = false;
			// 
			// btnOK
			// 
			this.btnOK.Location = new System.Drawing.Point(8, 120);
			this.btnOK.Name = "btnOK";
			this.btnOK.TabIndex = 4;
			this.btnOK.Text = "OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(112, 120);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 5;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// ZipCodeDlg
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(194, 152);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "ZipCodeDlg";
			this.ShowInTaskbar = false;
			this.Text = "Add by zip code dialog";
			this.TopMost = true;
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion


		/// <summary>
		/// The Ok button click
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
    private void btnOK_Click(object sender, System.EventArgs e)
		{
      //set the dialog result
			this.DialogResult = DialogResult.OK;

      //close the dialog
			this.Close();
		}

    /// <summary>
    /// Cancel button click
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
		private void btnCancel_Click(object sender, System.EventArgs e)
		{
      //set the dialog result
			this.DialogResult = DialogResult.Cancel;

      //close the dialog
			this.Close();
		}

    /// <summary>
    /// Returns the zipCode entered by the user
    /// </summary>
		public long ZipCode
		{
			get 
			{ 
        //make sure that the zipcode is a number
				if(IsNumber(txtZipCode.Text))
					return long.Parse(txtZipCode.Text); 
				else
					return 0;
			}	
		}

    /// <summary>
    /// Returns whether the user checked the option to zoom to the given zipCode weather item
    /// </summary>
		public bool ZoomToItem
		{
			get { return chkZoomTo.Checked; }
		}

		/// <summary>
		/// test whether a string is a number
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
    private bool IsNumber(string input) 
		{
			foreach(char c in input) 
			{
				if(!char.IsNumber(c)) return false;
			}
			return true;
		}
	}
}

[Visual Basic .NET]

ZipCodeDlg.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms

	''' <summary>
	''' Gets the input zipCode from the user
	''' </summary>
	Public Class ZipCodeDlg : Inherits System.Windows.Forms.Form
		Private txtZipCode As System.Windows.Forms.TextBox
		Private lblZipCode As System.Windows.Forms.Label
		Private chkZoomTo As System.Windows.Forms.CheckBox
		Private groupBox1 As System.Windows.Forms.GroupBox
		Private WithEvents btnOK As System.Windows.Forms.Button
		Private WithEvents btnCancel As System.Windows.Forms.Button
		''' <summary>
		''' Required designer variable.
		''' </summary>
		Private components As System.ComponentModel.Container = Nothing

		Public Sub New()
			'
			' Required for Windows Form Designer support
			'
			InitializeComponent()
		End Sub

		''' <summary>
		''' Clean up any resources being used.
		''' </summary>
		Protected Overrides Overloads 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

		#Region "Windows Form Designer generated code"
		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			Me.txtZipCode = New System.Windows.Forms.TextBox()
			Me.lblZipCode = New System.Windows.Forms.Label()
			Me.chkZoomTo = New System.Windows.Forms.CheckBox()
			Me.groupBox1 = New System.Windows.Forms.GroupBox()
			Me.btnOK = New System.Windows.Forms.Button()
			Me.btnCancel = New System.Windows.Forms.Button()
			Me.groupBox1.SuspendLayout()
			Me.SuspendLayout()
			' 
			' txtZipCode
			' 
			Me.txtZipCode.Location = New System.Drawing.Point(64, 24)
			Me.txtZipCode.Name = "txtZipCode"
			Me.txtZipCode.TabIndex = 0
			Me.txtZipCode.Text = ""
			' 
			' lblZipCode
			' 
			Me.lblZipCode.Location = New System.Drawing.Point(8, 24)
			Me.lblZipCode.Name = "lblZipCode"
			Me.lblZipCode.Size = New System.Drawing.Size(48, 16)
			Me.lblZipCode.TabIndex = 1
			Me.lblZipCode.Text = "ZipCode:"
			' 
			' chkZoomTo
			' 
			Me.chkZoomTo.Location = New System.Drawing.Point(8, 56)
			Me.chkZoomTo.Name = "chkZoomTo"
			Me.chkZoomTo.TabIndex = 2
			Me.chkZoomTo.Text = "Zoom to item"
			' 
			' groupBox1
			' 
			Me.groupBox1.Controls.Add(Me.chkZoomTo)
			Me.groupBox1.Controls.Add(Me.txtZipCode)
			Me.groupBox1.Controls.Add(Me.lblZipCode)
			Me.groupBox1.Location = New System.Drawing.Point(8, 8)
			Me.groupBox1.Name = "groupBox1"
			Me.groupBox1.Size = New System.Drawing.Size(176, 88)
			Me.groupBox1.TabIndex = 3
			Me.groupBox1.TabStop = False
			' 
			' btnOK
			' 
			Me.btnOK.Location = New System.Drawing.Point(8, 120)
			Me.btnOK.Name = "btnOK"
			Me.btnOK.TabIndex = 4
			Me.btnOK.Text = "OK"
'			Me.btnOK.Click += New System.EventHandler(Me.btnOK_Click);
			' 
			' btnCancel
			' 
			Me.btnCancel.Location = New System.Drawing.Point(112, 120)
			Me.btnCancel.Name = "btnCancel"
			Me.btnCancel.TabIndex = 5
			Me.btnCancel.Text = "Cancel"
'			Me.btnCancel.Click += New System.EventHandler(Me.btnCancel_Click);
			' 
			' ZipCodeDlg
			' 
			Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
			Me.ClientSize = New System.Drawing.Size(194, 152)
			Me.Controls.Add(Me.btnCancel)
			Me.Controls.Add(Me.btnOK)
			Me.Controls.Add(Me.groupBox1)
			Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
			Me.Name = "ZipCodeDlg"
			Me.ShowInTaskbar = False
			Me.Text = "Add by zip code dialog"
			Me.TopMost = True
			Me.groupBox1.ResumeLayout(False)
			Me.ResumeLayout(False)

		End Sub
		#End Region


		''' <summary>
		''' The Ok button click
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
	Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
	  'set the dialog result
			Me.DialogResult = System.Windows.Forms.DialogResult.OK

	  'close the dialog
			Me.Close()
	End Sub

	''' <summary>
	''' Cancel button click
	''' </summary>
	''' <param name="sender"></param>
	''' <param name="e"></param>
		Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
	  'set the dialog result
			Me.DialogResult = DialogResult.Cancel

	  'close the dialog
			Me.Close()
		End Sub

	''' <summary>
	''' Returns the zipCode entered by the user
	''' </summary>
		Public ReadOnly Property ZipCode() As Long
			Get
		'make sure that the zipcode is a number
				If IsNumber(txtZipCode.Text) Then
					Return Long.Parse(txtZipCode.Text)
				Else
					Return 0
				End If
			End Get
		End Property

	''' <summary>
    ''' Returns whether the user checked the option to zoom to the given zipCode weather item
	''' </summary>
		Public ReadOnly Property ZoomToItem() As Boolean
			Get
				Return chkZoomTo.Checked
			End Get
		End Property

		''' <summary>
    ''' test whether a string is a number
		''' </summary>
		''' <param name="input"></param>
		''' <returns></returns>
	Private Function IsNumber(ByVal input As String) As Boolean
			For Each c As Char In input
				If (Not Char.IsNumber(c)) Then
				Return False
				End If
			Next c
			Return True
	End Function
	End Class