📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace wxwinter.wf.UDPCommunication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
send.sendMsg(this.textBox1.Text);
}
UDPListen listen;
UDPSend send;
System.Threading.Thread 线程;
private void Form1_Load(object sender, EventArgs e)
{
listen = new UDPListen("192.168.1.30",7788);
System.Threading.ThreadStart 线程方法;
线程方法 = new System.Threading.ThreadStart(listen.open);
listen.msgReceiptEvent += new msgReceiptHandler(listen_msgReceiptEvent);
线程 = new System.Threading.Thread(线程方法);
线程.Start();
send = new UDPSend("192.168.1.30", 7788);
}
//当收到请求数据时,事件
private void listen_msgReceiptEvent(object sender, msgReceiptEventArg e)
{
this.Invoke(new ThreadUIHandle(ThreadUIHandleMethod), new object[] { e.data });
}
delegate void ThreadUIHandle(object data);
void ThreadUIHandleMethod(object data)
{
this.textBox2.Text = data.ToString();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
listen.close();
线程.Abort();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -