home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Wintalk / CS / ConnectDialog.cs next >
Encoding:
Text File  |  2000-06-23  |  5.3 KB  |  184 lines

  1. /*+==========================================================================
  2.   File:      ConnectDialog.cs
  3.  
  4.   Summary:   WFC Dialog (implementation through the Form class).  This 
  5.              window displays two edit boxes (host and port), and OK and 
  6.              Cancel buttons.  OnCommand is overrided to correctly handle 
  7.              events when the respective buttons are clicked.
  8.  
  9.   Classes:   ConnectDialog
  10.  
  11.   Functions: Dispose, button1_click, ConnectDialog_closing, InitForm
  12.              
  13. ----------------------------------------------------------------------------
  14.   This file is part of the Microsoft NGWS Samples.
  15.  
  16.   Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  17. ==========================================================================+*/
  18.  
  19. using System;
  20. using System.WinForms;
  21. using System.ComponentModel;
  22. using System.Drawing;
  23.  
  24. public class ConnectDialog : Form
  25. {
  26.     public String host = null;
  27.     public int port = 0;
  28.     
  29.     public bool AllowClose = true;
  30.                          
  31. /*****************************************************************************
  32.  Constructor : ConnectDialog
  33.  
  34.  Abstract:     Constructs an instance of ConnectDialog
  35.             
  36.  Input Parameters: (none)
  37.  
  38. ******************************************************************************/
  39.     public ConnectDialog()
  40.     {
  41.         InitForm();        
  42.     }
  43.  
  44. /*****************************************************************************
  45.  Function :    Dispose
  46.  
  47.  Abstract:     Overrides Form.Dispose, cleans up the component list.
  48.             
  49.  Input Parameters: (None)
  50.  
  51.  Returns: void
  52. ******************************************************************************/
  53.     public override void Dispose()
  54.     {
  55.         base.Dispose();
  56.         components.Dispose();
  57.     }
  58.  
  59. /*****************************************************************************
  60.  Function :    button1_click
  61.  
  62.  Abstract:     Invoked when the "Connect" button is clicked.  Validates input
  63.                and stores the host and port information into member 
  64.                variables.
  65.             
  66.  Input Parameters: source(Object), e(EventArgs)
  67.  
  68.  Returns: Void
  69. ******************************************************************************/
  70.     private void button1_click(Object source, EventArgs e)
  71.     {
  72.         host = edit1.Text.Trim();
  73.         if (host.Equals("")) {
  74.             AllowClose = false;
  75.             MessageBox.Show(this,"Please enter a valid host","Wintalk");
  76.             return;
  77.         }
  78.         Console.WriteLine("host = " + host);
  79.         try {
  80.             port = Convert.ToInt32(edit2.Text);
  81.         }
  82.         catch {
  83.             AllowClose = false;
  84.             MessageBox.Show(this,"Please enter a valid port number","Wintalk");
  85.             return;
  86.         }
  87.         Console.WriteLine("port = " + port.ToString());
  88.     }
  89.  
  90. /*****************************************************************************
  91.  Function:     ConnectDialog_closing
  92.  
  93.  Abstract:     Invoked when the ConnectDialog is closing.  
  94.             
  95.  Input Parameters: source(Object), e(EventArgs)
  96.  
  97.  Returns: Void
  98. ******************************************************************************/
  99.     private void ConnectDialog_closing(Object source, CancelEventArgs e)
  100.     {
  101.         if (!AllowClose) {
  102.             e.Cancel = true;
  103.             AllowClose = true;
  104.         }
  105.     }
  106.     
  107.     Container components = new Container();
  108.     Label label1 = new Label();
  109.     TextBox edit1 = new TextBox();
  110.     Label label2 = new Label();
  111.     TextBox edit2 = new TextBox();
  112.     Button button1 = new Button();
  113.     Button button2 = new Button();
  114.  
  115. /*****************************************************************************
  116.  Function :    InitForm
  117.  
  118.  Abstract:     Creates UI elements (buttons, edit controls, ...) on the 
  119.                ConnectDialog WFC form.
  120.             
  121.  Input Parameters: None
  122.  
  123.  Returns: Void
  124. ******************************************************************************/
  125.     private void InitForm()
  126.     {
  127.         label1.Location = new Point(11, 12);
  128.         label1.Size =  (Size) new Point(30, 13);
  129.         label1.TabIndex = 4;
  130.         label1.TabStop = false;
  131.         label1.Text = "Host:";
  132.  
  133.         edit1.Location = new Point(46, 8);
  134.         edit1.Size = (Size) new Point(245, 20);
  135.         edit1.TabIndex = 0;
  136.         edit1.Text = "localhost";
  137.  
  138.         label2.Location = new Point(11, 38);
  139.         label2.Size = (Size) new Point(30, 13);
  140.         label2.TabIndex = 5;
  141.         label2.TabStop = false;
  142.         label2.Text = "Port:";
  143.  
  144.         edit2.Location = new Point(46, 34);
  145.         edit2.Size = (Size) new Point(71, 20);
  146.         edit2.TabIndex = 1;
  147.         edit2.Text = "5000";
  148.  
  149.         button1.Location = new Point(56, 67);
  150.         button1.Size = (Size) new Point(81, 22);
  151.         button1.TabIndex = 2;
  152.         button1.Text = "Connect";
  153.         button1.DialogResult = DialogResult.OK;
  154.         button1.AddOnClick(new EventHandler(this.button1_click));
  155.  
  156.         button2.Location = new Point(164, 67);
  157.         button2.Size = (Size) new Point(81, 22);
  158.         button2.TabIndex = 3;
  159.         button2.Text = "Cancel";
  160.         button2.DialogResult = DialogResult.Cancel;
  161.  
  162.         this.Text = "Connect";
  163.         this.AcceptButton = button1;
  164.         this.AutoScaleBaseSize = (Size) new Point(5, 13);
  165.         this.BorderStyle = FormBorderStyle.FixedSingle;
  166.         this.CancelButton = button2;
  167.         this.ClientSize =  (Size) new Point(300, 95);
  168.         this.MaximizeBox = false;
  169.         this.MinimizeBox = false;
  170.         this.ShowInTaskbar = false;
  171.         this.StartPosition = FormStartPosition.CenterParent;
  172.         this.AddOnClosing(new CancelEventHandler(this.ConnectDialog_closing));
  173.  
  174.         this.Controls.All = (new Control[] {
  175.                             button2, 
  176.                             button1, 
  177.                             edit2, 
  178.                             label2, 
  179.                             edit1, 
  180.                             label1});
  181.     }
  182.  
  183. }
  184.