.net版本聊天室源碼

聊天室.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="聊天室.aspx.cs" Inherits="_10_25.聊天室" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        #ltmessage
        {
            height: 189px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr><td colspan="4">在線聊天:<img src="pic.aspx" />人</td></tr>
    <tr><td colspan="4"><div id="ltmessage" runat="server"></div></td></tr>
            <tr><td colspan="3">請輸入你的姓名:</td><td><asp:TextBox ID="name" runat="server" 
                    Width="228px"></asp:TextBox></td></tr>
    <tr><td>請選擇表情:</td>
        <td><asp:DropDownList ID="DropDownList1" runat="server" 
                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Value="悲傷">悲傷</asp:ListItem>
            <asp:ListItem Value="暈">暈</asp:ListItem>
            <asp:ListItem>高興</asp:ListItem>
        </asp:DropDownList>
    </td></tr>
            <tr><td colspan="3">請輸入你的消息:</td><td>
                <asp:TextBox ID="message" runat="server" 
                    Height="116px" Width="224px"></asp:TextBox></td></tr>
    <tr><td colspan="3"><asp:Button ID="Button1" runat="server" Text="發送消息" 
            οnclick="Button1_Click" /></td><td>
        <asp:Button ID="Button2" runat="server" Text="清除日誌" οnclick="Button2_Click" /></td></tr>
    </table>
    </div>
    
    </form>
</body>
</html>

聊天室.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _10_25
{
    public partial class 聊天室 : System.Web.UI.Page
    {
        Dictionary<string, string> img;
        protected void Page_Load(object sender, EventArgs e)
        {
             img= new Dictionary<string, string>();
             if (!IsPostBack)
             {
                 ltmessage.InnerHtml = Application["ms"].ToString() + "<br/>";
             }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           
            switch (DropDownList1.SelectedValue)
            {
                case "高興":
                    img["圖片"] = "<img src=img/高興.gif/ width='20px'>";
                    break;
                case "悲傷":
                    img["圖片"] = "<img src=img/悲傷.gif/ width='20px'>";
                    break;
                case "暈":
                    img["圖片"] = "<img src=img/暈.gif/ width='20px'>";
                    break;
            }

            Application.Lock();
            Application["ms"] = Application["ms"] + "<br/>" + name.Text + ":" + message.Text + img["圖片"];
            Application.UnLock();
            string msg = Application["ms"].ToString();
            ltmessage.InnerHtml = msg;
            if (msg.Length >= 500)
            {
                Application["ms"] = "";
            }

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            ltmessage.InnerHtml = "";
        }
    }
}

global.asax:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace _10_25
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Application["count"] = 0;
            Application["ms"] = "";
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            Application["count"] = Convert.ToInt32(Application["count"]) + 1;
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application["count"] = Convert.ToInt32(Application["count"]) - 1;
        }

        protected void Application_End(object sender, EventArgs e)
        {
           
        }
    }
}

pic.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _10_25
{
    public partial class pic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(20, 20))
            {
                using(System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
                {
                    g.Clear(System.Drawing.Color.White);
                    g.DrawString(Application["count"].ToString(), new System.Drawing.Font("宋體", 20), System.Drawing.Brushes.Blue, 0, 0);
                }
                bitmap.Save(Response.OutputStream , System.Drawing.Imaging.ImageFormat.Jpeg);
            }
           

        }
    }
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章