看板 C_Sharp 關於我們 聯絡資訊
提供兩個骯髒的 Method, 針對跨執行緒變更 UI 的問題. //設定控制項的 Text 屬性 Ctrl.SetText(textBox1, "TextValue"); //將 textBox1.Text 設為 "TextValue" //設定控制項的任一屬性值 Ctrl.SetValue(textBox1, "Visible", false); //將 textBox1 設為不可見 //CtrlHelper public static class Ctrl { public static void SetValue( Control ctrl, string property, object value) { if (ctrl.InvokeRequired) { Action<Control, string, object> d = new Action<Control, string, object>(SetValue); ctrl.Invoke(d, ctrl, property, value); return; } ctrl.GetType().GetProperty(property) .SetValue(ctrl, value, null); } public static void SetText( Control ctrl, string value) { SetValue(ctrl, "Text", value); } } -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.161.40.29