Commit | Line | Data |
---|---|---|
75af24f1 LOK |
1 | using System; |
2 | using System.Windows.Forms; | |
3 | ||
4 | namespace CecConfigGui | |
5 | { | |
6 | public class AsyncForm : Form | |
7 | { | |
8 | delegate void SetControlEnabledCallback(Control control, bool val); | |
9 | public void SetControlEnabled(Control control, bool val) | |
10 | { | |
11 | if (control.InvokeRequired) | |
12 | { | |
13 | SetControlEnabledCallback d = new SetControlEnabledCallback(SetControlEnabled); | |
14 | try | |
15 | { | |
16 | this.Invoke(d, new object[] { control, val }); | |
17 | } | |
18 | catch (Exception) { } | |
19 | } | |
20 | else | |
21 | { | |
22 | control.Enabled = val; | |
23 | } | |
24 | } | |
25 | ||
26 | delegate void SetControlTextCallback(Control control, string val); | |
27 | public void SetControlText(Control control, string val) | |
28 | { | |
29 | if (control.InvokeRequired) | |
30 | { | |
31 | SetControlTextCallback d = new SetControlTextCallback(SetControlText); | |
32 | try | |
33 | { | |
34 | this.Invoke(d, new object[] { control, val }); | |
35 | } | |
36 | catch (Exception) { } | |
37 | } | |
38 | else | |
39 | { | |
40 | control.Text = val; | |
41 | } | |
42 | } | |
43 | ||
44 | delegate void SetCheckboxCheckedCallback(CheckBox control, bool val); | |
45 | public void SetCheckboxChecked(CheckBox control, bool val) | |
46 | { | |
47 | if (control.InvokeRequired) | |
48 | { | |
49 | SetCheckboxCheckedCallback d = new SetCheckboxCheckedCallback(SetCheckboxChecked); | |
50 | try | |
51 | { | |
52 | this.Invoke(d, new object[] { control, val }); | |
53 | } | |
54 | catch (Exception) { } | |
55 | } | |
56 | else | |
57 | { | |
58 | control.Checked = val; | |
59 | } | |
60 | } | |
61 | ||
2b3c67ec LOK |
62 | delegate void SetCheckboxItemCheckedCallback(CheckedListBox control, int index, bool val); |
63 | public void SetCheckboxItemChecked(CheckedListBox control, int index, bool val) | |
64 | { | |
65 | if (control.InvokeRequired) | |
66 | { | |
67 | SetCheckboxItemCheckedCallback d = new SetCheckboxItemCheckedCallback(SetCheckboxItemChecked); | |
68 | try | |
69 | { | |
70 | this.Invoke(d, new object[] { control, index, val }); | |
71 | } | |
72 | catch (Exception) { } | |
73 | } | |
74 | else | |
75 | { | |
76 | control.SetItemChecked(index, val); | |
77 | } | |
78 | } | |
79 | ||
75af24f1 LOK |
80 | delegate void SetProgressValueCallback(ProgressBar control, int val); |
81 | public void SetProgressValue(ProgressBar control, int val) | |
82 | { | |
83 | if (control.InvokeRequired) | |
84 | { | |
85 | SetProgressValueCallback d = new SetProgressValueCallback(SetProgressValue); | |
86 | try | |
87 | { | |
88 | this.Invoke(d, new object[] { control, val }); | |
89 | } | |
90 | catch (Exception) { } | |
91 | } | |
92 | else | |
93 | { | |
94 | control.Value = val; | |
95 | } | |
96 | } | |
97 | ||
98 | delegate void SetComboBoxItemsCallback(ComboBox control, string selectedText, object[] val); | |
99 | public void SetComboBoxItems(ComboBox control, string selectedText, object[] val) | |
100 | { | |
101 | if (control.InvokeRequired) | |
102 | { | |
103 | SetComboBoxItemsCallback d = new SetComboBoxItemsCallback(SetComboBoxItems); | |
104 | try | |
105 | { | |
106 | this.Invoke(d, new object[] { control, selectedText, val }); | |
107 | } | |
108 | catch (Exception) { } | |
109 | } | |
110 | else | |
111 | { | |
112 | control.Items.Clear(); | |
113 | control.Items.AddRange(val); | |
114 | control.Text = selectedText; | |
115 | } | |
116 | } | |
117 | ||
118 | delegate void SetControlVisibleCallback(Control control, bool val); | |
119 | public void SetControlVisible(Control control, bool val) | |
120 | { | |
121 | if (control.InvokeRequired) | |
122 | { | |
123 | SetControlVisibleCallback d = new SetControlVisibleCallback(SetControlVisible); | |
124 | try | |
125 | { | |
126 | this.Invoke(d, new object[] { control, val }); | |
127 | } | |
128 | catch (Exception) { } | |
129 | } | |
130 | else | |
131 | { | |
132 | control.Visible = val; | |
133 | } | |
134 | } | |
5b8c2761 LOK |
135 | |
136 | delegate void DisplayDialogCallback(Form control, bool modal); | |
137 | public void DisplayDialog(Form control, bool modal) | |
138 | { | |
139 | if (this.InvokeRequired) | |
140 | { | |
141 | DisplayDialogCallback d = new DisplayDialogCallback(DisplayDialog); | |
142 | try | |
143 | { | |
144 | this.Invoke(d, new object[] { control, modal }); | |
145 | } | |
146 | catch (Exception) { } | |
147 | } | |
148 | else | |
149 | { | |
150 | if (modal) | |
151 | control.ShowDialog(this); | |
152 | else | |
153 | control.Show(this); | |
154 | } | |
155 | } | |
75af24f1 LOK |
156 | } |
157 | } |