home *** CD-ROM | disk | FTP | other *** search
- /*+==========================================================================
- File: ConnectDialog.cpp
-
- 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-1999 Microsoft Corporation. All rights reserved.
- ==========================================================================+*/
-
- #using <mscorlib.dll>
- #using <System.DLL>
- #using <System.WinForms.DLL>
- #using <System.Drawing.DLL>
- #using <Microsoft.Win32.Interop.DLL>
-
- using namespace System;
- using namespace System::WinForms;
- using namespace System::ComponentModel;
- using namespace System::Drawing;
-
- #define NULL 0
-
- #include "ConnectDialog.h"
-
- /*****************************************************************************
- Function : Dispose
-
- Abstract: Overrides Form.Dispose, cleans up the component list.
-
- Input Parameters: (None)
-
- Returns: void
- ******************************************************************************/
- void ConnectDialog::Dispose()
- {
- Form::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
- ******************************************************************************/
- void ConnectDialog::button1_click(Object *source, EventArgs *e)
- {
- host = edit1->Text->Trim();
- if (host->Equals(S"")) {
- AllowClose = false;
- MessageBox::Show(this,S"Please enter a valid host",S"Wintalk");
- return;
- }
- Console::WriteLine(String::Concat(S"host = ", host));
- try {
- port = Convert::ToInt32(edit2->Text);
- }
- catch (Exception *ex) {
- AllowClose = false;
- MessageBox::Show(this,S"Please enter a valid port number",S"Wintalk");
- return;
- }
- Console::WriteLine(String::Concat(S"port = ", port.ToString()));
- }
-
- /*****************************************************************************
- Function: ConnectDialog_closing
-
- Abstract: Invoked when the ConnectDialog is closing.
-
- Input Parameters: source(Object), e(EventArgs)
-
- Returns: Void
- ******************************************************************************/
- void ConnectDialog::ConnectDialog_closing(Object *source, CancelEventArgs *e)
- {
- if (!AllowClose) {
- e->Cancel = true;
- AllowClose = true;
- }
- }
-
-
-
- /*****************************************************************************
- Function : InitForm
-
- Abstract: Creates UI elements (buttons, edit controls, ...) on the
- ConnectDialog WFC form.
-
- Input Parameters: None
-
- Returns: Void
- ******************************************************************************/
- void ConnectDialog::InitForm()
- {
- label1->Location = *new Point(11, 12);
- label1->Size = *new System::Drawing::Size(*new Point(30, 13));
- label1->TabIndex = 4;
- label1->TabStop = false;
- label1->Text = S"Host:";
-
- edit1->Location = *new Point(46, 8);
- edit1->Size = *new System::Drawing::Size(*new Point(245, 20));
- edit1->TabIndex = 0;
- edit1->Text = S"localhost";
-
- label2->Location = *new Point(11, 38);
- label2->Size = *new System::Drawing::Size(*new Point(30, 13));
- label2->TabIndex = 5;
- label2->TabStop = false;
- label2->Text = S"Port:";
-
- edit2->Location = *new Point(46, 34);
- edit2->Size = *new System::Drawing::Size(*new Point(71, 20));
- edit2->TabIndex = 1;
- edit2->Text = S"5000";
-
- button1->Location = *new Point(56, 67);
- button1->Size = *new System::Drawing::Size(*new Point(81, 22));
- button1->TabIndex = 2;
- button1->Text = S"Connect";
- button1->DialogResult = DialogResult::OK;
- button1->AddOnClick(new EventHandler(this, &ConnectDialog::button1_click));
-
- button2->Location = *new Point(164, 67);
- button2->Size = *new System::Drawing::Size(*new Point(81, 22));
- button2->TabIndex = 3;
- button2->Text = S"Cancel";
- button2->DialogResult = DialogResult::Cancel;
-
- this->Text = S"Connect";
- this->AcceptButton = button1;
- this->AutoScaleBaseSize = *new System::Drawing::Size(*new Point(5, 13));
- this->BorderStyle = FormBorderStyle::FixedSingle;
- this->CancelButton = button2;
- this->ClientSize = *new System::Drawing::Size(*new Point(300, 95));
- this->MaximizeBox = false;
- this->MinimizeBox = false;
- this->ShowInTaskbar = false;
- this->StartPosition = FormStartPosition::CenterParent;
- this->AddOnClosing(new CancelEventHandler(this, &ConnectDialog::ConnectDialog_closing));
-
- Control *c[] = new Control*[6];
- c[0] = button2;
- c[1] = button1;
- c[2] = edit2;
- c[3] = label2;
- c[4] = edit1;
- c[5] = label1;
-
- this->Controls->All = c;
- }
-
-