?? 用c#實現類似qq的簡單通訊程序.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0064)http://5550.blog.ccidnet.com/blog/ccid/do_showone/tid_18245.html -->
<HTML><HEAD><TITLE>用c#實現類似QQ的簡單通訊程序 - 樸楓 -- IT博客—IT人的新家園</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content=index,follow name=robots>
<META content=IT博客—IT人的新家園 name=keywords><LINK title="RSS 2.0"
href="http://blog.ccidnet.com/rss.php?uid=3873" type=application/rss+xml
rel=alternate>
<STYLE>BODY {
FONT-SIZE: 12px; BACKGROUND: #ffffff; MARGIN: 0px; FONT-FAMILY: verdana,arial,helvetica; TEXT-ALIGN: center
}
FORM {
DISPLAY: inline; MARGIN: 0px
}
TD {
BORDER-RIGHT: 1px; BORDER-TOP: 0px; FONT-SIZE: 9pt
}
.content {
FONT-SIZE: 12px; COLOR: #2d2d2d; LINE-HEIGHT: 17px; TEXT-DECORATION: none
}
.comment {
BORDER-RIGHT: #373737 1px dashed; PADDING-RIGHT: 4px; BORDER-TOP: #373737 1px dashed; PADDING-LEFT: 4px; PADDING-BOTTOM: 4px; BORDER-LEFT: #373737 1px dashed; COLOR: #373737; PADDING-TOP: 4px; BORDER-BOTTOM: #373737 1px dashed; BACKGROUND-COLOR: #ffffff
}
A {
LINE-HEIGHT: 160%; TEXT-DECORATION: none
}
A:hover {
TEXT-DECORATION: underline
}
.p9 {
FONT-SIZE: 9pt; COLOR: #ffffff; LINE-HEIGHT: 17px; FONT-FAMILY: "Arial", "Helvetica", "sans-serif", "宋體"; TEXT-DECORATION: none
}
.p13 {
FONT-SIZE: 13px; COLOR: #000000; LINE-HEIGHT: 18px; TEXT-DECORATION: none
}
.p14 {
FONT-SIZE: 14px; COLOR: #000000; LINE-HEIGHT: 20px; TEXT-DECORATION: none
}
.p17 {
FONT-SIZE: 18px; COLOR: #01007f; LINE-HEIGHT: 22px; TEXT-DECORATION: none
}
.p18 {
FONT-WEIGHT: bold; FONT-SIZE: 18px; COLOR: #000000; LINE-HEIGHT: 23px; FONT-FAMILY: "黑體"; TEXT-DECORATION: none
}
.p19 {
FONT-SIZE: 20px; COLOR: #000000; LINE-HEIGHT: 30px; TEXT-DECORATION: none
}
.yinying {
FILTE: DropShadow(Color=#0033bb, OffX=1, OffY=1, Positive=1)
}
.time {
FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: "Arial", "Helvetica", "sans-serif"; TEXT-DECORATION: none
}
.side_center {
PADDING-RIGHT: 2px; PADDING-LEFT: 2px; FONT-SIZE: 12px; PADDING-BOTTOM: 2px; PADDING-TOP: 2px; TEXT-ALIGN: center
}
.side_calendar {
FONT-WEIGHT: bold; FONT-SIZE: 16px
}
.bp16_4 {
FONT-SIZE: 16px; COLOR: #1584a6; LINE-HEIGHT: 22px; TEXT-DECORATION: none
}
.subject {
FONT-SIZE: 16px; COLOR: #1584a6; LINE-HEIGHT: 22px; TEXT-DECORATION: none
}
.xml {
BORDER-RIGHT: #8c8e7b 1px solid; BORDER-TOP: #8c8e7b 1px solid; BACKGROUND: #ffffff; BORDER-LEFT: #8c8e7b 1px solid; BORDER-BOTTOM: #8c8e7b 1px solid; FONT-FAMILY: Tahoma, Verdana
}
.xml A {
COLOR: #ffffff
}
.xml_1 {
FONT-SIZE: 7pt; BACKGROUND: #ff6500; COLOR: #ffffff
}
.xml_2 {
FONT-SIZE: 7pt; BACKGROUND: #8c8e7b; COLOR: #ffffff
}
.notice {
FONT-SIZE: 9pt; COLOR: #ffffff; LINE-HEIGHT: 19px; TEXT-DECORATION: none
}
</STYLE>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginwidth="0">
<TABLE class=content cellSpacing=0 cellPadding=5 width=760 border=0>
<TBODY>
<TR>
<TD><IMG height=47 src="用c#實現類似QQ的簡單通訊程序.files/1213_logo.gif"
width=154></TD>
<TD vAlign=baseline align=right><A class=content
href="http://blog.ccidnet.com/index/ccid/index.html">博客首頁</A> | <A
class=content href="http://blog.ccidnet.com/search/ccid/index.html">搜索</A>
| <A class=content
href="http://blog.ccidnet.com/login/ccid/index.html">登錄</A> | <A
class=content
href="http://blog.ccidnet.com/register/ccid/index.html">注冊</A>
</TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=760
background=用c#實現類似QQ的簡單通訊程序.files/1209-bg-1.gif border=0>
<TBODY>
<TR>
<TD><IMG height=7 src="用c#實現類似QQ的簡單通訊程序.files/blank.gif"
width=20></TD></TR></TBODY></TABLE>
<TABLE height=110 cellSpacing=0 cellPadding=0 width=760
background=用c#實現類似QQ的簡單通訊程序.files/760110b.gif border=0>
<TBODY>
<TR>
<TD align=middle>
<TABLE class=p18 cellSpacing=1 cellPadding=1 width=300 bgColor=#444444
border=0>
<TBODY>
<TR>
<TD class=p18 bgColor=#f3f4e1><B><IMG height=18
src="用c#實現類似QQ的簡單通訊程序.files/blank.gif"
width=10>樸楓</B></TD></TR></TBODY></TABLE><BR>
<TABLE class=content cellSpacing=1 cellPadding=1 width=300 bgColor=#444444
border=0>
<TBODY>
<TR>
<TD bgColor=#f3f4e1><B><IMG height=12
src="用c#實現類似QQ的簡單通訊程序.files/blank.gif" width=10></B><A class=content
href="http://mtv.blog.ccidnet.com/">http://mtv.blog.ccidnet.com/</A>
<BR>
>><A class=content
onclick="clipboardData.setData('Text','http://mtv.blog.ccidnet.com');alert('復制鏈接成功,請推薦給好友!');"
href="javascript:">復制</A> >><A class=content
onclick="window.external.addFavorite('http://mtv.blog.ccidnet.com','用c#實現類似QQ的簡單通訊程序 - 樸楓 -- IT博客—IT人的新家園');"
href="javascript:">收藏本頁</A></TD></TR></TBODY></TABLE></TD>
<TD width=221></TD></TR></TBODY></TABLE><IMG height=3
src="用c#實現類似QQ的簡單通訊程序.files/blank.gif" width=20><BR>
<TABLE cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD style="BORDER-RIGHT: #bbd8e2 1px solid; BORDER-LEFT: #bbd8e2 1px solid"
vAlign=top align=middle>
<TABLE class=p9 cellSpacing=0 cellPadding=3 width="100%" bgColor=#449fbb
border=0>
<TBODY>
<TR>
<TD>
<MARQUEE onmouseover=this.stop() onmouseout=this.start()
scrollAmount=4 direction=level height="100%"><A class=notice
href="http://blog.ccidnet.com/" target=_blank>賽迪博客</A><FONT
class=notice>系統公告:</FONT> <A class=notice
href="http://blog.ccidnet.com/notice.php?aid=7"
target=_blank>企業廣告發布規定</A> <A class=notice
href="http://blog.ccidnet.com/notice.php?aid=4"
target=_blank>春天換新裝,博客要扮靚</A> <A
class=notice href="http://blog.ccidnet.com/notice.php?aid=9"
target=_blank>IT博客征文進行中!</A> <A class=notice
href="http://blog.ccidnet.com/notice.php?aid=11" target=_blank>IBM
developerWorks 專區新版上線</A>
</MARQUEE></TD></TR></TBODY></TABLE><IMG height=3
src="用c#實現類似QQ的簡單通訊程序.files/blank.gif" width=20><BR>
<TABLE class=content cellSpacing=0 cellPadding=3 width="100%"
bgColor=#bbd8e2 border=0>
<TBODY>
<TR>
<TD><IMG height=10 hspace=5
src="用c#實現類似QQ的簡單通訊程序.files/1209-icon-4.gif" width=9 align=absMiddle
vspace=1> <SPAN
style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word"><A class=content
href="http://mtv.blog.ccidnet.com/blog/ccid/uid_3873.html"><B>全部文章</B></A>
</SPAN></TD></TR></TBODY></TABLE><IMG height=8
src="用c#實現類似QQ的簡單通訊程序.files/blank.gif" width=20><BR>
<TABLE class=content cellSpacing=0 cellPadding=2 width="95%" border=0>
<TBODY>
<TR>
<TD align=middle><SPAN class=p19><B>用c#實現類似QQ的簡單通訊程序</B>
</SPAN><BR>作者: lhuam 發表日期: 2006-01-12 12:35 文章屬性: 原創 <A
class=content
title=http://mtv.blog.ccidnet.com/blog/ccid/do_showone/tid_18245.html
onclick="clipboardData.setData('Text','http://mtv.blog.ccidnet.com/blog/ccid/do_showone/tid_18245.html'); alert('復制鏈接成功,請推薦好友!');"
href="javascript:">復制鏈接</A> </TD></TR>
<TR>
<TD>
<DIV class=content
style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word"><BR><BR><SPAN
class=content>本文介紹了用c#實現的一個類似QQ的局域網通訊程序,當點擊最小化程序跑到系統托盤里,雙擊托盤可以可以顯示主頁面。<BR>程序運行界面如下:<BR><B></B><BR><IMG
height=479 src="用c#實現類似QQ的簡單通訊程序.files/10_3873_5c9207776c8bb20.jpg"
width=304 border=0><BR><BR>托盤里的菜單如下:<BR><B></B><BR><IMG height=69
src="用c#實現類似QQ的簡單通訊程序.files/10_3873_5c86dac55b1bcec.jpg" width=129
border=0><BR><BR>c#作為微軟.Net戰略的重要棋子,對網絡編程提供了很好的支持和優化。實現起來特別方便,還是看代碼吧,已經注釋的很清楚了。工程文件放在后面了,需要的可以下載<BR>代碼如下:<BR>using
System;<BR>using System.Drawing;<BR>using
System.Collections;<BR>using System.ComponentModel;<BR>using
System.Windows.Forms;<BR>using System.Data;<BR>using
System.IO;<BR>using System.Net.Sockets;<BR>using
System.Threading;<BR>namespace p2pChat<BR>{<BR> ///
<summary><BR> /// MainForm 的摘要說明。<BR>
/// </summary><BR> public class MainForm :
System.Windows.Forms.Form<BR> {<BR>
private System.Windows.Forms.Label label1;<BR>
private System.Windows.Forms.Label label2;<BR>
private System.Windows.Forms.TextBox
txtIp;<BR> private
System.Windows.Forms.TextBox txtRecord;<BR>
private System.Windows.Forms.TextBox txtName;<BR>
private System.Windows.Forms.Button
btnSend;<BR> private
System.Windows.Forms.TextBox txtContent;<BR>
private TcpListener tcpLister = new TcpListener(5566);
<BR> System.Threading.ThreadStart
listenPort;<BR> System.Threading.Thread
lister;<BR> private
System.Windows.Forms.Label label3; <BR>
System.Windows.Forms.NotifyIcon NotifyIcon1;<BR>
//托盤里顯示的圖標,我用的是QQ里的寵物狗的圖標<BR>
private Icon img = new
Icon(@"C:\OpenPet.ico");<BR>
System.Windows.Forms.ContextMenu nMenu;<BR>
/// <summary><BR> ///
必需的設計器變量。<BR> ///
</summary><BR> private
System.ComponentModel.Container components = null;<BR>
public MainForm()<BR>
{<BR> //<BR>
// Windows
窗體設計器支持所必需的<BR>
//<BR>
InitializeComponent();<BR><BR>
//不顯示最大化按鈕<BR>
this.MaximizeBox = false; <BR>
//最小化時不顯示在任務欄<BR>
this.ShowInTaskbar =
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -