/// <summary> /// 在ListBox中追加状态信息 /// </summary> /// <param name="str">要追加的信息</param> private void AddItemToListBox(string str) { if (lst_Status.InvokeRequired) { AddItemToListBoxDelegate d = AddItemToListBox; lst_Status.Invoke(d, str); } else { lst_Status.Items.Add(str); if (!File.Exists("Log.txt")) { FileStream fs1 = new FileStream("Log.txt", FileMode.Create, FileAccess.Write); //创建写入文件 StreamWriter sw = new StreamWriter(fs1); sw.WriteLine(str); //开始写入值 sw.Close(); fs1.Close(); } else { //FileStream fs = new FileStream("Log.txt", FileMode.Open, FileAccess.Write); FileStream fs = File.Open("Log.txt", FileMode.Append, FileAccess.Write); StreamWriter sr = new StreamWriter(fs); sr.WriteLine(str);//开始写入值 sr.Close(); fs.Close(); } lst_Status.SelectedIndex = lst_Status.Items.Count - 1; lst_Status.ClearSelected(); } }
/// <summary>在ListBox中追加状态信息</summary> /// <param name="str">要追加的信息</param> private void AddItemToListBox(string str) { if (R_ReceiveMessage.InvokeRequired) { AddItemToListBoxDelegate d = AddItemToListBox; R_ReceiveMessage.Invoke(d, str); } else { R_ReceiveMessage.AppendText(str + Environment.NewLine); } }
/// <summary> /// 在ListBox中追加状态信息 /// </summary> /// <param name="str">要追加的信息</param> private void AddItemToListBox(string str) { if (lst_runlog.InvokeRequired) { AddItemToListBoxDelegate d = AddItemToListBox; lst_runlog.Invoke(d, str); } else { lst_runlog.Items.Add(str); lst_runlog.SelectedIndex = lst_runlog.Items.Count - 1; lst_runlog.ClearSelected(); } }
/// <summary> /// 在ListBox中追加状态信息 /// </summary> /// <param name="str">要追加的信息</param> private void AddItemToListBox(string str) { if (stateslistBox.InvokeRequired) { AddItemToListBoxDelegate d = AddItemToListBox; stateslistBox.Invoke(d, str); } else { stateslistBox.Items.Add(str); stateslistBox.SelectedIndex = stateslistBox.Items.Count - 1; stateslistBox.ClearSelected(); } }
private void AddItemToListBox(string str) { if (listBox1.InvokeRequired) { AddItemToListBoxDelegate d = AddItemToListBox; listBox1.Invoke(d, str); } else { listBox1.Items.Add(str); listBox1.TopIndex = listBox1.Items.Count - 1; listBox1.ClearSelected(); } }
/// <summary> /// ListBox中追加状态信息 /// </summary> /// <param name="str">要追加的信息</param> private void AddItemToListBox(string str) { if (listBoxStatus.InvokeRequired) { AddItemToListBoxDelegate d = new AddItemToListBoxDelegate(AddItemToListBox); listBoxStatus.Invoke(d, str); } else { listBoxStatus.Items.Add(str); listBoxStatus.SelectedIndex = listBoxStatus.Items.Count - 1; listBoxStatus.ClearSelected(); } }
//委托函数—在listview中添加活动IP public void AddText(string text) { //判断是否能当前线程调用 if (this.IPList.InvokeRequired) { AddItemToListBoxDelegate d = new AddItemToListBoxDelegate(AddText); this.Invoke(d, text); } else { MessageBox.Show(text); IPList.Items.Add(text); } }
private void RemoveItemToListBox2(string str) { if (listBox2.InvokeRequired) { AddItemToListBoxDelegate d = RemoveItemToListBox2; listBox2.Invoke(d, str); } else { listBox2.Items.Remove(str); listBox2.SelectedIndex = listBox2.Items.Count - 1; listBox2.ClearSelected(); } }
void AddItemToListBox(string str) { if (!listBox.Dispatcher.CheckAccess()) { AddItemToListBoxDelegate d = AddItemToListBox; listBox.Dispatcher.Invoke(d, str); } else { listBox.Items.Add(str); listBox.SelectedIndex = listBox.Items.Count - 1; //listBox.ClearSelected(); } }
/// <summary> /// 向ListBox中添加状态信息 /// </summary> /// <param name="message">要添加的信息字符串</param> private void AddItemToListBox(string message) { // InvokeRequired代表如果调用线程与创建控件的线程不在一个线程上时,则返回true // 否则返回false if (listboxStatus.InvokeRequired) { AddItemToListBoxDelegate listboxdelegate = AddItemToListBox; listboxStatus.Invoke(listboxdelegate, message); } else { listboxStatus.Items.Add(message); listboxStatus.TopIndex = listboxStatus.Items.Count - 1; listboxStatus.ClearSelected(); } }
/// <summary> /// 在listBox_Chats消息记录中追加信息 /// </summary> /// <param name="str">要追加的信息</param> private void AddChatsToList(IBaseRequestInfo baseInfo) { try { if (rtbMsgList.InvokeRequired) { AddItemToListBoxDelegate d = AddChatsToList; rtbMsgList.Invoke(d, baseInfo); } else { switch (baseInfo.MsgType) { case MsgType.Text: TextRequestInfo textInfo = (TextRequestInfo)baseInfo; rtbMsgList.SelectionStart = rtbMsgList.Text.Length; //设置插入符位置为文本框末 if (this.txtUserName.Text != textInfo.FromUserName) { rtbMsgList.SelectionColor = Color.Blue; //设置文本颜色 } else { rtbMsgList.SelectionColor = Color.Green; //设置文本颜色 } rtbMsgList.AppendText(textInfo.FromUserName + "(" + Utils.GetDateTime() + ")\r\n"); rtbMsgList.SelectionStart = rtbMsgList.Text.Length; //设置插入符位置为文本框末 rtbMsgList.SelectionColor = Color.Black; //设置文本颜色 rtbMsgList.AppendText(textInfo.Content + "\r\n"); break; case MsgType.Error: ErrorRequestInfo errorInfo = (ErrorRequestInfo)baseInfo; MessageBox.Show(this, errorInfo.Content); txtUserName.Enabled = true; this.btnLogin.Enabled = true; this.buttom_Send.Enabled = false; break; } } } catch { } }