国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

用c#實現類似QQ的簡單通訊程序

2024-07-21 02:24:52
字體:
來源:轉載
供稿:網友

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.io;
using system.net.sockets;
using system.threading;
namespace p2pchat
{
  ///
  /// mainform 的摘要說明。
  ///
  public class mainform : system.windows.forms.form
  {
    private system.windows.forms.label label1;
    private system.windows.forms.label label2;
    private system.windows.forms.textbox txtip;
    private system.windows.forms.textbox txtrecord;
    private system.windows.forms.textbox txtname;
    private system.windows.forms.button btnsend;
    private system.windows.forms.textbox txtcontent;

    private tcplistener tcplister = new tcplistener(5566);
    system.threading.threadstart listenport;
    system.threading.thread lister;
    private system.windows.forms.label label3;
    system.windows.forms.notifyicon notifyicon1;
    //托盤里顯示的圖標,我用的是qq里的寵物狗的圖標
    private icon img = new icon(@"c:/openpet.ico");
    system.windows.forms.contextmenu nmenu;
    ///
    /// 必需的設計器變量。
    ///
    private system.componentmodel.container components = null;
    public mainform()
    {
        //
        // windows 窗體設計器支持所必需的
        //
        initializecomponent();

        //不顯示最大化按鈕
        this.maximizebox = false;
        //最小化時不顯示在任務欄
        this.showintaskbar = false;
 listenport += new threadstart(this.listen);
        lister = new thread(listenport);
        this.closing += new system.componentmodel.canceleventhandler(abortlister);
        initializenotifyicon();
        //
        // todo: 在 initializecomponent 調用后添加任何構造函數代碼
        //
    }
    #region 初始化托盤組件
    private void initializenotifyicon()
    {
        notifyicon1 = new notifyicon();
        notifyicon1.icon = img;
        notifyicon1.text = "局域網聊天程序";
        notifyicon1.visible = true;
        notifyicon1.doubleclick += new eventhandler(this.showmainform);

        menuitem [] menuarray = new menuitem[3];
        menuarray[0] = new menuitem();
        menuarray[0].text = "顯示主窗口";
        menuarray[0].click += new eventhandler(this.showmainform);
        menuarray[0].defaultitem = true;

        menuarray[1] = new menuitem("-");

        menuarray[2] = new menuitem();
        menuarray[2].text = "退出";
        menuarray[2].click += new eventhandler(this.exitsystem);

        nmenu = new contextmenu(menuarray);
        notifyicon1.contextmenu = nmenu;
    }
    //顯示主窗口
    private void showmainform(object sender,system.eventargs e)
    {
        this.windowstate = system.windows.forms.formwindowstate.normal;
    }
    //退出程序
    private void exitsystem(object sender,system.eventargs e)
    {
        notifyicon1.visible = false;
        this.close();
    }
    #endregion
    ///
    /// 清理所有正在使用的資源。
    ///
    protected override void dispose( bool disposing )
    {
        if( disposing )
        {
         if (components != null)
         {
            components.dispose();
         }
        }
       base.dispose( disposing );
    }
    #region windows 窗體設計器生成的代碼
    ///
    /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
    /// 此方法的內容。
    ///
    private void initializecomponent()
{

        this.label1 = new system.windows.forms.label();
        this.txtip = new system.windows.forms.textbox();
        this.txtrecord = new system.windows.forms.textbox();
        this.label2 = new system.windows.forms.label();
        this.txtname = new system.windows.forms.textbox();
        this.btnsend = new system.windows.forms.button();
        this.txtcontent = new system.windows.forms.textbox();
        this.label3 = new system.windows.forms.label();
        this.suspendlayout();
        //
        // label1
        //
        this.label1.location = new system.drawing.point(16, 232);
        this.label1.name = "label1";
        this.label1.size = new system.drawing.size(72, 23);
        this.label1.tabindex = 0;
        this.label1.text = "目標地址:";
        this.label1.textalign = system.drawing.contentalignment.middlecenter;
        //
        // txtip
        //
        this.txtip.anchor = ((system.windows.forms.anchorstyles)((system.windows.forms.anchorstyles.left | system.windows.forms.anchorstyles.right)));
        this.txtip.location = new system.drawing.point(80, 232);
        this.txtip.name = "txtip";
        this.txtip.size = new system.drawing.size(200, 21);
        this.txtip.tabindex = 1;
        this.txtip.text = "";
        //
        // txtrecord
        //
        this.txtrecord.anchor = ((system.windows.forms.anchorstyles)((system.windows.forms.anchorstyles.left | system.windows.forms.anchorstyles.right)));
        this.txtrecord.location = new system.drawing.point(16, 32);
        this.txtrecord.multiline = true;
        this.txtrecord.name = "txtrecord";
        this.txtrecord.readonly = true;
        this.txtrecord.scrollbars = system.windows.forms.scrollbars.vertical;
        this.txtrecord.size = new system.drawing.size(264, 176);
        this.txtrecord.tabindex = 4;
        this.txtrecord.text = "";
        //
        // label2
        //
        this.label2.location = new system.drawing.point(24, 256);
        this.label2.name = "label2";
        this.label2.size = new system.drawing.size(48, 23);
        this.label2.tabindex = 5;
        this.label2.text = "呢 稱:";
        this.label2.textalign = system.drawing.contentalignment.middlecenter;
        //
        // txtname
        //
        this.txtname.location = new system.drawing.point(80, 256);
        this.txtname.name = "txtname";
        this.txtname.size = new system.drawing.size(88, 21);
        this.txtname.tabindex = 6;
        this.txtname.text = "";
        //
        // btnsend
        //
        this.btnsend.location = new system.drawing.point(200, 256);
        this.btnsend.name = "btnsend";
        this.btnsend.size = new system.drawing.size(64, 23);
        this.btnsend.tabindex = 0;
        this.btnsend.text = "發 送";
        this.btnsend.click += new system.eventhandler(this.btnsend_click);
        //
        // txtcontent
        //
        this.txtcontent.anchor = ((system.windows.forms.anchorstyles)(((system.windows.forms.anchorstyles.bottom | system.windows.forms.anchorstyles.left)
         | system.windows.forms.anchorstyles.right)));
        this.txtcontent.location = new system.drawing.point


 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武川县| 长白| 平泉县| 高密市| 宜川县| 乐都县| 琼海市| 牡丹江市| 徐州市| 湖南省| 瓮安县| 巍山| 乡宁县| 广宗县| 大港区| 甘谷县| 京山县| 辽阳市| 仁怀市| 浮山县| 太和县| 云林县| 临安市| 南康市| 中山市| 谢通门县| 万安县| 东台市| 青岛市| 积石山| 皮山县| 宜兰市| 会宁县| 蓝田县| 南木林县| 泸溪县| 苗栗县| 神农架林区| 乐昌市| 安阳县| 平远县|