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

📄 26.4.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 26.4 Using Infrared with Windows Forms
using System;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;
namespace _7_IRChatClient
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox tbTranscript;
private System.Windows.Forms.TextBox tbMessage;
private System.Windows.Forms.Button btnSend;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem mnuExit;
// the name used for this IR service
private string serviceType = “IRDA_CHAT”;
public Form1()
{
InitializeComponent();
}
/* Windows Form Designer Generated Code */
private void AddMessage( string name, string message )
{
tbTranscript.Text += name + “: “ + message + “\r\n”;
tbTranscript.ScrollToCaret();
}
private void btnSend_Click(object sender, System.EventArgs e)
{
int numTries = 0;
const int numRetries = 5;
IrDAClient client = null; // the client to send data to
// disable the send button and display the wait cursor
btnSend.Enabled = false;
Cursor.Current = Cursors.WaitCursor;
do
{
try
{
// find a device to send data to
client = new IrDAClient( serviceType );
}
catch( Exception ex )
{
if( numTries >= numRetries-1 )
{
// add a message to the transcript TextBox
AddMessage(“Error”,”cannot send message-”+ex.Message);
// enable button, reset cursor, clear message TextBox
btnSend.Enabled = true;
tbMessage.Text = “”;
Cursor.Current = Cursors.Default;
return;
}
}
numTries++;
} while( (client == null) && (numTries < numRetries ));
// to be continued...

⌨️ 快捷键说明

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