.net版本聊天室源码

21 篇文章 0 订阅
聊天室.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);
            }
           

        }
    }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值