当前位置:编程学习 > C#/ASP.NET >>

急!!!我用C#做了个简单的聊天软件可是想实现改变发送消息的字体和颜色如何做到?

我只是做到了再没发送之前可以改变,但是一旦发送了,接收端也会随着我的改变而改变,我想我这端口改变字体,接收端可以接收,但是它发送的消息不会根据我的字体改变而改变如何做到?我刚学C#是个菜鸟请大虾们帮忙
 private void button2_Click(object sender, EventArgs e)-----button2是我的发送按钮
        {
            try
            {
                IPAddress[] ip = Dns.GetHostAddresses(Dns.GetHostName());
                string strmsg = " " + txtName.Text + "(" + ip[0].ToString() + ") " + DateTime.Now.ToLongTimeString() + "\n" + "  " + this.rtbSend.Text + "\n";
                TcpClient client = new TcpClient(txtIP.Text, 888);
                NetworkStream netstream = client.GetStream();
                StreamWriter wstream = new StreamWriter(netstream, Encoding.Default);
                wstream.Write(strmsg);
                wstream.Flush();
                wstream.Close();
                client.Close();
                rtbContent.AppendText(strmsg);
                rtbContent.SelectionColor = colorDialog1.Color;-----我是在发送的地方添加了这2行代码
                rtbContent.SelectionFont = fontDialog1.Font;-------
               
                
                rtbContent.ScrollToCaret();
                rtbSend.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void StartListen()
        {
            message = "";
            tcpListener = new TcpListener(888);
            tcpListener.Start();
            while (true)
            {
                TcpClient tclient = tcpListener.AcceptTcpClient();  //接受连接请求
                NetworkStream nstream = tclient.GetStream();        //获取数据流
                byte[] mbyte = new byte[1024];                      //建立缓存
                int i = nstream.Read(mbyte, 0, mbyte.Length);       //将数据流写入缓存
                message = Encoding.Default.GetString(mbyte, 0, i);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            rtbContent.Clear();
        }
   private void 设置字体颜色ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
          
            colorDialog1.AllowFullOpen = true;
            colorDialog1.AnyColor = true;
            colorDialog1.SolidColorOnly = false;
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                if (rtbSend.SelectedRtf == "")
                {
                    rtbSend.SelectAll();
                }
                rtbSend.SelectionColor = colorDialog1.Color;
            }
            

        }

        private void 设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            fontDialog1.AllowVectorFonts = true;
            fontDialog1.AllowVerticalFonts = true;
            fontDialog1.FixedPitchOnly = false;
            fontDialog1.MaxSize = 72;
            fontDialog1.MinSize = 4;
            if (fontDialog1.ShowDialog() == DialogResult.OK)
            {
                if (rtbSend.SelectedRtf == "")
                {
                    rtbSend.SelectAll();

                }
                rtbSend.SelectionFont = fontDialog1.Font;
            } --------------------编程问答-------------------- rtbContent.AppendText(strmsg);
  rtbContent.SelectionColor = colorDialog1.Color;-----我是在发送的地方添加了这2行代码
  rtbContent.SelectionFont = fontDialog1.Font;-------

改成
  rtbContent.SelectionColor = colorDialog1.Color;-----我是在发送的地方添加了这2行代码
  rtbContent.SelectionFont = fontDialog1.Font;-------
在追加到rtbContent里面赋值颜色和字体看看
rtbContent.AppendText(strmsg);
--------------------编程问答-------------------- 为什么不用所见即所得控件?
--------------------编程问答-------------------- http://msdn.microsoft.com/zh-cn/library/system.windows.forms.fontdialog%28VS.80%29.aspx 对from不熟悉。看帮助吧。
if (colorDialog1.ShowDialog() == DialogResult.OK)
  {
  if (rtbSend.SelectedRtf == "")
  {
  rtbSend.SelectAll();
  }
  rtbSend.SelectionColor = colorDialog1.Color;
改成

if (colorDialog1.ShowDialog() == DialogResult.OK)
{
this.rtbSend.SelectionColor = colorDialog1.Color;
this.rtbSend.SelectionFont = colorDialog1.Font;

--------------------编程问答-------------------- 大虾我想的就是仅仅是我发送出去的消息做改变,不要我上面的IP地址啊,显示的时间啊字体颜色都改变如何更改呢 --------------------编程问答--------------------
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,