www.pudn.com > HttpProxy.rar > Port.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using HttpProxy.Component;
namespace HttpProxy.UI
{
///
/// Port 类
///
public class Port : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox gbxPort;
private System.Windows.Forms.TextBox txtPort;
public System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Port()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.gbxPort = new System.Windows.Forms.GroupBox();
this.txtPort = new System.Windows.Forms.TextBox();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.gbxPort.SuspendLayout();
this.SuspendLayout();
//
// gbxPort
//
this.gbxPort.Controls.Add(this.txtPort);
this.gbxPort.Location = new System.Drawing.Point(24, 16);
this.gbxPort.Name = "gbxPort";
this.gbxPort.Size = new System.Drawing.Size(232, 48);
this.gbxPort.TabIndex = 0;
this.gbxPort.TabStop = false;
this.gbxPort.Text = "端口";
//
// txtPort
//
this.txtPort.Location = new System.Drawing.Point(24, 17);
this.txtPort.MaxLength = 5;
this.txtPort.Name = "txtPort";
this.txtPort.Size = new System.Drawing.Size(192, 21);
this.txtPort.TabIndex = 0;
this.txtPort.Text = "8090";
//
// btnOk
//
this.btnOk.Font = new System.Drawing.Font("宋体", 9F);
this.btnOk.Location = new System.Drawing.Point(40, 72);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(64, 24);
this.btnOk.TabIndex = 1;
this.btnOk.Text = "启 动";
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// btnCancel
//
this.btnCancel.Font = new System.Drawing.Font("宋体", 9F);
this.btnCancel.Location = new System.Drawing.Point(144, 72);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(64, 24);
this.btnCancel.TabIndex = 1;
this.btnCancel.Text = "取 消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// Port
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(272, 110);
this.ControlBox = false;
this.Controls.Add(this.btnOk);
this.Controls.Add(this.gbxPort);
this.Controls.Add(this.btnCancel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.MaximizeBox = false;
this.Name = "Port";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "HttpProxy 端口";
this.gbxPort.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnOk_Click(object sender, System.EventArgs e)
{
try
{
ProxyMain.sbpGlobal.Text="正在启动服务...";
int port=Convert.ToInt32(this.txtPort.Text.Trim());
ProxyMain.Server=new ProxyServer();
ProxyMain.Server.ListenCount=ProxyMain.ListenCount;
ProxyMain.Server.Port=port;
ProxyMain.Server.Start();
ProxyMain.ServerStarted=true;
ProxyMain.sbpGlobal.Text="代理服务已启动!";
Showlog();
this.Close();
}
catch
{
MessageBox.Show("请输入合理端口!","HttpProxy",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
///
/// Showlogs this instance.
///
private void Showlog()
{
if(ProxyMain.MasterLogOpen==false)
{
MasterLog child=new MasterLog();
child.MdiParent=ProxyMain.Global;
child.Show();
ProxyMain.MasterLogOpen=true;
}
else
{
for(int i=0;i