主题:怎样添加Accept的事件
如题,关键是事件的声明!!!
using System;
using System.Windows.Forms;
using System.Net.Sockets;
namespace SocketServer
{
public class Server:Form
{
private TcpListener listen;
private Button btStart;
private Button btStop;
public Server()
{
listen = new TcpListener(1000);
btStart = new Button();
btStop = new Button();
this.Width = 135;
this.Height = 70;
this.MaximizeBox = false;
btStart.Text = "启动";
btStart.Left = 10;
btStart.Top = 10;
btStart.Width = 50;
btStart.Height = 20;
btStop.Text = "停止";
btStop.Left = 70;
btStop.Top = 10;
btStop.Width = 50;
btStop.Height = 20;
btStart.Click += new EventHandler(btStart_Click);
btStop.Click += new EventHandler(btStop_Click);
this.Controls.Add(btStart);
this.Controls.Add(btStop);
}
private void btStart_Click(object sender, EventArgs e)
{
listen.Start();
}
private void btStop_Click(object sender, EventArgs e)
{
listen.Stop();
}
public static void Main()
{
Application.Run(new Server());
}
}
}
using System;
using System.Windows.Forms;
using System.Net.Sockets;
namespace SocketServer
{
public class Server:Form
{
private TcpListener listen;
private Button btStart;
private Button btStop;
public Server()
{
listen = new TcpListener(1000);
btStart = new Button();
btStop = new Button();
this.Width = 135;
this.Height = 70;
this.MaximizeBox = false;
btStart.Text = "启动";
btStart.Left = 10;
btStart.Top = 10;
btStart.Width = 50;
btStart.Height = 20;
btStop.Text = "停止";
btStop.Left = 70;
btStop.Top = 10;
btStop.Width = 50;
btStop.Height = 20;
btStart.Click += new EventHandler(btStart_Click);
btStop.Click += new EventHandler(btStop_Click);
this.Controls.Add(btStart);
this.Controls.Add(btStop);
}
private void btStart_Click(object sender, EventArgs e)
{
listen.Start();
}
private void btStop_Click(object sender, EventArgs e)
{
listen.Stop();
}
public static void Main()
{
Application.Run(new Server());
}
}
}