资源简介
本实例演示定义委托,并利用委托把来自串口接收到的数据显示在文本框中!熟悉委托的定义和串行数据收发的简单功能!
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
///
/// 定义委托
///
///
public delegate void ShowString(string a);
///
/// 字符显示在文本框
///
///
public void ShowTxt(string a)
{
this.textBox1.AppendText(DateTime.Now.ToString() + “ | “ + a + “\n“);
if (textBox1.TextLength > 2000)
{
textBox1.Clear();
}
}
///
/// 定义委托并初始化
///
ShowString AA;
///
/// 接收字符串存储
///
string ReadStr = ““;
public Form1()
{
InitializeComponent();
serialPort1.Open();
AA = new ShowString(ShowTxt);//初始化委托
}
//串口收到数据并回发
private void serialPort1_DataReceived(object sender System.IO.Ports.SerialDataReceivedEventArgs e)
{
ReadStr = serialPort1.ReadExisting();
byte[] ReadBuffer;
ReadBuffer= System.Text.ASCIIEncoding.ASCII.GetBytes(ReadStr);
this.Invoke(AA ReadStr);
serialPort1.Write(ReadBuffer 0 ReadBuffer.Length);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10752 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
文件 30208 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
文件 11600 2014-12-10 20:43 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
文件 490 2010-03-17 22:39 WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
文件 1669 2014-12-10 20:45 WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
文件 2936 2014-12-10 20:45 WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
文件 6016 2014-12-10 20:45 WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
文件 374 2014-12-10 20:05 WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs
文件 1969 2014-12-10 20:05 WindowsFormsApplication1\WindowsFormsApplication1\Form2.Designer.cs
文件 5817 2014-12-10 20:05 WindowsFormsApplication1\WindowsFormsApplication1\Form2.resx
文件 2164 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6441 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 614 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.read.1.tlog
文件 1476 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\GenerateResource.write.1.tlog
文件 1366 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
文件 10752 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.exe
文件 180 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
文件 180 2014-12-10 20:05 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form2.resources
文件 30208 2014-12-10 20:47 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.pdb
文件 180 2014-12-10 20:05 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
文件 507 2014-12-10 20:05 WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
文件 1398 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
文件 2899 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
文件 5612 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
文件 1110 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
文件 249 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
文件 4011 2014-12-10 20:05 WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
文件 914 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1.sln
..A..H. 20992 2014-12-10 20:45 WindowsFormsApplication1\WindowsFormsApplication1.suo
目录 0 2014-12-10 20:03 WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\TempPE
............此处省略11个文件信息
- 上一篇:c# GUI+ 多种仪表盘显示
- 下一篇:c#红绿灯程序源代码,c#红绿灯程序源代码
相关资源
- c#红绿灯程序源代码,c#红绿灯程序源
- c# GUI+ 多种仪表盘显示
- C#无焦点后台读取扫码枪信息
- C# Http协议上传文件有进度条
- 数据库办公室日常信息管理系统c#源程
- C# Winfrom 嵌入 EXCEL
- wince5.0下C#绘制仪表盘控件及Demo源码
- C#标准正态分布类库
- C#串口通信上位机源代码
- 选择文件 选择文件 ( C#_DataTable控件
- C#文件粉碎机
- C#高级编程第10版带源码
- c#客户端与服务器端的开发经典案例
- 点阵字体文件查看工具 C# 源码
- 使用C#调用GDAL库读取GeoTIFF高程数据
- [c#]图片二值化研究源代码
- c shap 。net做报表,很不错
- C# 图片分割器,将一个大图分割为指
- C#简单实现凯撒密码算法
- c# Report 报表设计工具 设计布局打印
- C# WPF 状态栏图标特效 类似QQ/MSN的状态
- C# 生成三层架构代码
- C#窗体Winform,鼠标悬停在控件上,提
- C#设计模式第二版.pdf
- C#获取网络标准时间
- C#聊天程序
-
c#xm
l读写demo - C#与CoDeSys共享内存例程
- C#编写的图像均衡化、去噪、高斯模糊
- 图斑净面积计算工具源代码基于ARCG
评论
共有 条评论