Re: [問題] Text方法會丟出未知的例外?

看板C_Sharp作者 (wvsrugby)時間15年前 (2009/05/22 00:21), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/4 (看更多)
提供兩個骯髒的 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
文章代碼(AID): #1A5N-HC6 (C_Sharp)
文章代碼(AID): #1A5N-HC6 (C_Sharp)