我只是做到了再没发送之前可以改变,但是一旦发送了,接收端也会随着我的改变而改变,我想我这端口改变字体,接收端可以接收,但是它发送的消息不会根据我的字体改变而改变如何做到?我刚学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;
}
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.SelectionColor = colorDialog1.Color;-----我是在发送的地方添加了这2行代码
rtbContent.SelectionFont = fontDialog1.Font;-------改成
rtbContent.SelectionColor = colorDialog1.Color;-----我是在发送的地方添加了这2行代码
rtbContent.SelectionFont = fontDialog1.Font;-------
在追加到rtbContent里面赋值颜色和字体看看
rtbContent.AppendText(strmsg);
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;
}