⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.h

📁 网络编程入门
💻 H
字号:
#pragma once


namespace Example
{
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::Net;
	
	/// <summary> 
	/// Form1 摘要
	///
	/// 警告: 如果您更改该类的名称,则需要更改 
	///          与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
	///          “资源文件名”属性。  否则,
	///          设计器将不能与此窗体关联的
	///          本地化资源正确交互。
	/// </summary>
	public __gc class Form1 : public System::Windows::Forms::Form
	{	
	public:
		Form1(void)
		{
			InitializeComponent();
		}
  
	protected:
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}
	private: System::Windows::Forms::Label *  label1;
	private: System::Windows::Forms::TextBox *  textBox1;
	private: System::Windows::Forms::Label *  label2;
	private: System::Windows::Forms::RichTextBox *  richTextBox1;
	private: System::Windows::Forms::Button *  button1;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container * components;

		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->label1 = new System::Windows::Forms::Label();
			this->textBox1 = new System::Windows::Forms::TextBox();
			this->label2 = new System::Windows::Forms::Label();
			this->richTextBox1 = new System::Windows::Forms::RichTextBox();
			this->button1 = new System::Windows::Forms::Button();
			this->SuspendLayout();
			// 
			// label1
			// 
			this->label1->Location = System::Drawing::Point(8, 16);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(72, 16);
			this->label1->TabIndex = 0;
			this->label1->Text = S"主机地址:";
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(80, 8);
			this->textBox1->Name = S"textBox1";
			this->textBox1->Size = System::Drawing::Size(208, 21);
			this->textBox1->TabIndex = 1;
			this->textBox1->Text = S"";
			// 
			// label2
			// 
			this->label2->Location = System::Drawing::Point(8, 40);
			this->label2->Name = S"label2";
			this->label2->Size = System::Drawing::Size(72, 16);
			this->label2->TabIndex = 2;
			this->label2->Text = S"主机信息:";
			// 
			// richTextBox1
			// 
			this->richTextBox1->Location = System::Drawing::Point(8, 56);
			this->richTextBox1->Name = S"richTextBox1";
			this->richTextBox1->Size = System::Drawing::Size(280, 136);
			this->richTextBox1->TabIndex = 3;
			this->richTextBox1->Text = S"";
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(168, 32);
			this->button1->Name = S"button1";
			this->button1->Size = System::Drawing::Size(120, 23);
			this->button1->TabIndex = 4;
			this->button1->Text = S"获取主机信息";
			this->button1->Click += new System::EventHandler(this, button1_Click);
			// 
			// Form1
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(296, 198);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->richTextBox1);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->label1);
			this->MaximizeBox = false;
			this->Name = S"Form1";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = S"演示获取主机IP信息";
			this->ResumeLayout(false);

		}	
	private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
			 {//获取主机信息
				 this->richTextBox1->Clear();
				try
				{
					// 得到主机的信息,放到IPHostEntry实例中
					IPHostEntry* IPHost=Dns::Resolve(this->textBox1->Text);
					this->richTextBox1->AppendText(String::Concat("\n","HostName:",IPHost->HostName));					
				   // 从IPHostEntry实例中提取关于主机的信息并打印出来
					String* Aliases[]=IPHost->Aliases;
					this->richTextBox1->AppendText(String::Concat("\n","Count of host Aliases:",Aliases->Length.ToString()));					
					for(int i=0;i<Aliases->Length;i++)
					{
						this->richTextBox1->AppendText(String::Concat("\n",Aliases[i]));
					}					
		            IPAddress* addr[] = IPHost->AddressList;
					this->richTextBox1->AppendText(String::Concat("\n","Count of host addresses: ",addr->Length.ToString()));					
					this->richTextBox1->AppendText(String::Concat("\n","Host IP list:"));					
					for(int i= 0; i < addr->Length ; i++)
					{
						IPAddress* Addr=addr[i];
						this->richTextBox1->AppendText(String::Concat("\n",Addr->ToString()));										
					}
				}
				catch(Exception* Err)
				{
					MessageBox::Show(Err->Message,"信息提示",MessageBoxButtons::OK,MessageBoxIcon::Information);
				}
			 }

	};
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -