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 | { | |
a42ad439 | 13 | SetControlEnabledCallback d = SetControlEnabled; |
75af24f1 LOK |
14 | try |
15 | { | |
5cf99fae | 16 | Invoke(d, new object[] { control, val }); |
75af24f1 LOK |
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 | { | |
a42ad439 | 31 | SetControlTextCallback d = SetControlText; |
75af24f1 LOK |
32 | try |
33 | { | |
5cf99fae | 34 | Invoke(d, new object[] { control, val }); |
75af24f1 LOK |
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 | { | |
a42ad439 | 49 | SetCheckboxCheckedCallback d = SetCheckboxChecked; |
75af24f1 LOK |
50 | try |
51 | { | |
5cf99fae | 52 | Invoke(d, new object[] { control, val }); |
75af24f1 LOK |
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 | { | |
a42ad439 | 67 | SetCheckboxItemCheckedCallback d = SetCheckboxItemChecked; |
2b3c67ec LOK |
68 | try |
69 | { | |
5cf99fae | 70 | Invoke(d, new object[] { control, index, val }); |
2b3c67ec LOK |
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 | { | |
a42ad439 | 85 | SetProgressValueCallback d = SetProgressValue; |
75af24f1 LOK |
86 | try |
87 | { | |
5cf99fae | 88 | Invoke(d, new object[] { control, val }); |
75af24f1 LOK |
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 | { | |
a42ad439 | 103 | SetComboBoxItemsCallback d = SetComboBoxItems; |
75af24f1 LOK |
104 | try |
105 | { | |
5cf99fae | 106 | Invoke(d, new object[] { control, selectedText, val }); |
75af24f1 LOK |
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 | { | |
a42ad439 | 123 | SetControlVisibleCallback d = SetControlVisible; |
75af24f1 LOK |
124 | try |
125 | { | |
5cf99fae | 126 | Invoke(d, new object[] { control, val }); |
75af24f1 LOK |
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 | { | |
5cf99fae | 139 | if (InvokeRequired) |
5b8c2761 | 140 | { |
a42ad439 | 141 | DisplayDialogCallback d = DisplayDialog; |
5b8c2761 LOK |
142 | try |
143 | { | |
5cf99fae | 144 | Invoke(d, new object[] { control, modal }); |
5b8c2761 LOK |
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 | } |