home *** CD-ROM | disk | FTP | other *** search
- /*+==========================================================================
- File: ConnectDialog.cs
-
- Summary: WFC Dialog (implementation through the Form class). This
- window displays two edit boxes (host and port), and OK and
- Cancel buttons. OnCommand is overrided to correctly handle
- events when the respective buttons are clicked.
-
- Classes: ConnectDialog
-
- Functions: Dispose, button1_click, ConnectDialog_closing, InitForm
-
- ----------------------------------------------------------------------------
- This file is part of the Microsoft NGWS Samples.
-
- Copyright (C) 1998-2000 Microsoft Corporation. All rights reserved.
- ==========================================================================+*/
-
- using System;
- using System.WinForms;
- using System.ComponentModel;
- using System.Drawing;
-
- public class ConnectDialog : Form
- {
- public String host = null;
- public int port = 0;
-
- public bool AllowClose = true;
-
- /*****************************************************************************
- Constructor : ConnectDialog
-
- Abstract: Constructs an instance of ConnectDialog
-
- Input Parameters: (none)
-
- ******************************************************************************/
- public ConnectDialog()
- {
- InitForm();
- }
-
- /*****************************************************************************
- Function : Dispose
-
- Abstract: Overrides Form.Dispose, cleans up the component list.
-
- Input Parameters: (None)
-
- Returns: void
- ******************************************************************************/
- public override void Dispose()
- {
- base.Dispose();
- components.Dispose();
- }
-
- /*****************************************************************************
- Function : button1_click
-
- Abstract: Invoked when the "Connect" button is clicked. Validates input
- and stores the host and port information into member
- variables.
-
- Input Parameters: source(Object), e(EventArgs)
-
- Returns: Void
- ******************************************************************************/
- private void button1_click(Object source, EventArgs e)
- {
- host = edit1.Text.Trim();
- if (host.Equals("")) {
- AllowClose = false;
- MessageBox.Show(this,"Please enter a valid host","Wintalk");
- return;
- }
- Console.WriteLine("host = " + host);
- try {
- port = Convert.ToInt32(edit2.Text);
- }
- catch {
- AllowClose = false;
- MessageBox.Show(this,"Please enter a valid port number","Wintalk");
- return;
- }
- Console.WriteLine("port = " + port.ToString());
- }
-
- /*****************************************************************************
- Function: ConnectDialog_closing
-
- Abstract: Invoked when the ConnectDialog is closing.
-
- Input Parameters: source(Object), e(EventArgs)
-
- Returns: Void
- ******************************************************************************/
- private void ConnectDialog_closing(Object source, CancelEventArgs e)
- {
- if (!AllowClose) {
- e.Cancel = true;
- AllowClose = true;
- }
- }
-
- Container components = new Container();
- Label label1 = new Label();
- TextBox edit1 = new TextBox();
- Label label2 = new Label();
- TextBox edit2 = new TextBox();
- Button button1 = new Button();
- Button button2 = new Button();
-
- /*****************************************************************************
- Function : InitForm
-
- Abstract: Creates UI elements (buttons, edit controls, ...) on the
- ConnectDialog WFC form.
-
- Input Parameters: None
-
- Returns: Void
- ******************************************************************************/
- private void InitForm()
- {
- label1.Location = new Point(11, 12);
- label1.Size = (Size) new Point(30, 13);
- label1.TabIndex = 4;
- label1.TabStop = false;
- label1.Text = "Host:";
-
- edit1.Location = new Point(46, 8);
- edit1.Size = (Size) new Point(245, 20);
- edit1.TabIndex = 0;
- edit1.Text = "localhost";
-
- label2.Location = new Point(11, 38);
- label2.Size = (Size) new Point(30, 13);
- label2.TabIndex = 5;
- label2.TabStop = false;
- label2.Text = "Port:";
-
- edit2.Location = new Point(46, 34);
- edit2.Size = (Size) new Point(71, 20);
- edit2.TabIndex = 1;
- edit2.Text = "5000";
-
- button1.Location = new Point(56, 67);
- button1.Size = (Size) new Point(81, 22);
- button1.TabIndex = 2;
- button1.Text = "Connect";
- button1.DialogResult = DialogResult.OK;
- button1.AddOnClick(new EventHandler(this.button1_click));
-
- button2.Location = new Point(164, 67);
- button2.Size = (Size) new Point(81, 22);
- button2.TabIndex = 3;
- button2.Text = "Cancel";
- button2.DialogResult = DialogResult.Cancel;
-
- this.Text = "Connect";
- this.AcceptButton = button1;
- this.AutoScaleBaseSize = (Size) new Point(5, 13);
- this.BorderStyle = FormBorderStyle.FixedSingle;
- this.CancelButton = button2;
- this.ClientSize = (Size) new Point(300, 95);
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.ShowInTaskbar = false;
- this.StartPosition = FormStartPosition.CenterParent;
- this.AddOnClosing(new CancelEventHandler(this.ConnectDialog_closing));
-
- this.Controls.All = (new Control[] {
- button2,
- button1,
- edit2,
- label2,
- edit1,
- label1});
- }
-
- }
-