//委托使用文本框 void SetMyTextBoxValue(string value) { // Control.InvokeRequired 属性: 获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中。当前线程不是创建控件的线程时为true,当前线程中访问是False if (this.tb_ReceiveMessage.InvokeRequired) { SetTextBoxValue objSetTextBoxValue = new SetTextBoxValue(SetMyTextBoxValue); // IAsyncResult 接口:表示异步操作的状态。不同的异步操作需要不同的类型来描述,自然可以返回任何对象。 // Control.BeginInvoke 方法 (Delegate):在创建控件的基础句柄所在线程上异步执行指定委托。 IAsyncResult result = this.tb_ReceiveMessage.BeginInvoke(objSetTextBoxValue, new object[] { value }); try { objSetTextBoxValue.EndInvoke(result); } catch { } } else { this.tb_ReceiveMessage.Text += value + Environment.NewLine; this.tb_ReceiveMessage.SelectionStart = this.tb_ReceiveMessage.TextLength; this.tb_ReceiveMessage.ScrollToCaret(); } }
public void SetValue(string value) { if (tbox_result.InvokeRequired) { SetTextBoxValue setValueFunc = new SetTextBoxValue(SetValue); this.Invoke(setValueFunc, new object[] { value }); } else { //MessageBox.Show(tbox_result.Lines.Length.ToString()); if (tbox_result.Lines.Length > 50) { string[] lines = tbox_result.Lines; Array.Resize(ref lines, 50); tbox_result.Lines = lines; } tbox_result.Text = tbox_result.Text.Insert(0, value.ToString()); tbox_result.SelectAll(); tbox_result.SelectionColor = Color.Black; HighLightStr(tbox_result, "格式化成功", Color.Green, -1); HighLightStr(tbox_result, "创建应用成功", Color.Green, -1); HighLightStr(tbox_result, "创建应用出错", Color.Red, -1); HighLightStr(tbox_result, "格式化出错", Color.Red, -1); HighLightStr(tbox_result, "加载IDAEnroll出错", Color.Red, -1); } }
private void button2_Click(object sender, EventArgs e) { Form2 F2 = new Form2(); setTextBoxValue += F2.SetMessage; F2.Show(); }
public static LogUtil GetInstance(SetTextBoxValue setValueFunc) { if (instance == null) { instance = new LogUtil(setValueFunc); } return(instance); }
public void SetTextBox1Value(string str) { if (this.textBox1.InvokeRequired) { SetTextBoxValue objSetTextBoxValue = new SetTextBoxValue(SetTextBox1Value); IAsyncResult result = this.textBox1.BeginInvoke(objSetTextBoxValue, new object[] { str }); try { objSetTextBoxValue.EndInvoke(result); } catch { } } else { this.textBox1.Text = str; } }
//委托使用文本框 void SetMyTextBoxValue(Control c, string value) { // Control.InvokeRequired 属性: 获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中。当前线程不是创建控件的线程时为true,当前线程中访问是False if (c.InvokeRequired) { SetTextBoxValue objSetTextBoxValue = new SetTextBoxValue(SetMyTextBoxValue); // IAsyncResult 接口:表示异步操作的状态。不同的异步操作需要不同的类型来描述,自然可以返回任何对象。 // Control.BeginInvoke 方法 (Delegate):在创建控件的基础句柄所在线程上异步执行指定委托。 IAsyncResult result = this.tb_ReceiveMessage.BeginInvoke(objSetTextBoxValue, new object[] { c, value }); try { objSetTextBoxValue.EndInvoke(result); } catch { } } else { c.Text = value; } }
public FormChild( SetTextBoxValue set, GetTextBoxValue get) { InitializeComponent(); SetMainText = set; GetMainText = get; }
private void SetMyTextBoxValue(string value) { if (this.logSpace.InvokeRequired) { SetTextBoxValue objSetTextBoxValue = new SetTextBoxValue(SetMyTextBoxValue); IAsyncResult result = this.logSpace.BeginInvoke(objSetTextBoxValue, new object[] { value }); try { objSetTextBoxValue.EndInvoke(result); } catch { } } else { this.logSpace.Text = value; this.logSpace.SelectionStart = this.logSpace.TextLength; this.logSpace.ScrollToCaret(); } }
private LogUtil(SetTextBoxValue setValueFunc) { this.LogFunc = setValueFunc; }