-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmDynamicControl.frm
More file actions
324 lines (302 loc) · 8.82 KB
/
frmDynamicControl.frm
File metadata and controls
324 lines (302 loc) · 8.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
'frmDynamicControl
' Copyright (c) 2025 CM.Wang
' Freeware. Use at your own risk.
'#Region "Form"
#if defined(__FB_MAIN__) AndAlso Not defined(__MAIN_FILE__)
#define __MAIN_FILE__
#ifdef __FB_WIN32__
#cmdline "frmDynamicControl.rc"
#endif
Const _MAIN_FILE_ = __FILE__
#endif
#include once "mff/Form.bi"
#include once "mff/CheckBox.bi"
#include once "mff/CheckedListBox.bi"
#include once "mff/ComboBoxEdit.bi"
#include once "mff/CommandButton.bi"
#include once "mff/ImageBox.bi"
#include once "mff/Label.bi"
#include once "mff/ListControl.bi"
#include once "mff/Picture.bi"
#include once "mff/ProgressBar.bi"
#include once "mff/RadioButton.bi"
#include once "mff/TextBox.bi"
#include once "mff/TrackBar.bi"
Using My.Sys.Forms
Type Form3Type Extends Form
lstCtl As List
LstFrm As List
Declare Sub DeleteControl(ByRef Sender As Control Ptr)
Declare Sub CommandButton1_Click(ByRef Sender As Control)
Declare Sub Form_MouseMove(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
Declare Sub CheckBox2_Click(ByRef Sender As CheckBox)
Declare Sub Form_Destroy(ByRef Sender As Control)
Declare Constructor
Dim As CommandButton CommandButton1, CommandButton2, CommandButton3, CommandButton4
Dim As ComboBoxEdit ComboBoxEdit1
Dim As CheckBox CheckBox1, CheckBox2
Dim As Label Label1, Label2
End Type
Constructor Form3Type
' Form3
With This
.Name = "Form3"
.Text = "Dynamic Control Example"
.Designer = @This
.Caption = "Dynamic Control Example"
.OnMouseMove = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer), @Form_MouseMove)
.OnDestroy = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @Form_Destroy)
.SetBounds 0, 0, 650, 400
End With
' ComboBoxEdit1
With ComboBoxEdit1
.Name = "ComboBoxEdit1"
.Text = "ComboBoxEdit1"
.TabIndex = 0
.SetBounds 10, 10, 140, 21
.Designer = @This
.Parent = @This
.AddItem("CheckBox")
.AddItem("CheckedListBox")
.AddItem("ComboBoxEdit")
.AddItem("CommandButton")
.AddItem("ImageBox")
.AddItem("ListControl")
.AddItem("Picture")
.AddItem("ProgressBar")
.AddItem("RadioButton")
.AddItem("TextBox")
.AddItem("TrackBar")
'more controls...
.ItemIndex = 0
End With
' CheckBox1
With CheckBox1
.Name = "CheckBox1"
.Text = "Auto next"
.TabIndex = 1
.Caption = "Auto next"
.Checked = True
.SetBounds 10, 40, 140, 20
.Designer = @This
.Parent = @This
End With
' CommandButton1
With CommandButton1
.Name = "CommandButton1"
.Text = "Add control"
.TabIndex = 2
.Caption = "Add control"
.SetBounds 10, 70, 140, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton1_Click)
.Parent = @This
End With
' CommandButton2
With CommandButton2
.Name = "CommandButton2"
.Text = "Delete control"
.TabIndex = 3
.Caption = "Delete control"
.SetBounds 10, 100, 140, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton1_Click)
.Parent = @This
End With
' Label1
With Label1
.Name = "Label1"
.Text = "Control count: 0"
.TabIndex = 4
.Caption = "Control count: 0"
.SetBounds 10, 130, 140, 20
.Designer = @This
.Parent = @This
End With
' CommandButton3
With CommandButton3
.Name = "CommandButton3"
.Text = "Create form"
.TabIndex = 5
.Caption = "Create form"
.SetBounds 10, 280, 140, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton1_Click)
.Parent = @This
End With
' CommandButton4
With CommandButton4
.Name = "CommandButton4"
.Text = "Destroy form"
.TabIndex = 6
.Caption = "Destroy form"
.SetBounds 10, 310, 140, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton1_Click)
.Parent = @This
End With
' CheckBox2
With CheckBox2
.Name = "CheckBox2"
.Text = "Darkmode"
.TabIndex = 7
.Caption = "Darkmode"
.Checked = True
.SetBounds 10, 250, 140, 20
.Designer = @This
.OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As CheckBox), @CheckBox2_Click)
.Parent = @This
End With
' Label2
With Label2
.Name = "Label2"
.Text = "Form count: 0"
.TabIndex = 8
.Caption = "Form count: 0"
.SetBounds 10, 340, 140, 20
.Designer = @This
.Parent = @This
End With
End Constructor
Dim Shared Form3 As Form3Type
#if _MAIN_FILE_ = __FILE__
App.DarkMode = True
Form3.MainForm = True
Form3.Show
App.Run
#endif
'#End Region
Private Sub Form3Type.CommandButton1_Click(ByRef Sender As Control)
Dim i As Integer
Dim j As Integer
Dim y As Integer
Dim x As Integer
Select Case Sender.Name
Case "CommandButton1" 'Add control
Dim a As Control Ptr
Dim s As String = ComboBoxEdit1.Items.Item(ComboBoxEdit1.ItemIndex)
Select Case s
Case "CommandButton"
a = New CommandButton
Case "ComboBoxEdit"
a = New ComboBoxEdit
Case "CheckBox"
a = New CheckBox
Case "CheckedListBox"
a = New CheckedListBox
Case "ImageBox"
a = New ImageBox
a->BorderStyle= BorderStyles.bsClient
Case "ListControl"
a = New ListControl
Case "ProgressBar"
a = New ProgressBar
Case "RadioButton"
a = New RadioButton
Case "TextBox"
a = New TextBox
Case "Picture"
a = New Picture
a->BorderStyle= BorderStyles.bsClient
Case "TrackBar"
a = New TrackBar
Case Else
'more controls...
End Select
lstCtl.Add a
i = lstCtl.Count - 1
a->Name = s
a->Text = s & "_" & i
a->OnClick = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control), @CommandButton1_Click)
a->OnMouseMove = Cast(Sub(ByRef Designer As My.Sys.Object, ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer), @Form_MouseMove)
a->Hint = a->Name
This.Add a
x = i \ ComboBoxEdit1.ItemCount + 1
y = i Mod ComboBoxEdit1.ItemCount
a->Move x * 140 + (x + 1) * 10, y * 20 + (y + 1) * 10, 140, 20
a->Visible = True
Label1.Caption = "Control count: " & lstCtl.Count
If CheckBox1.Checked = False Then Exit Sub
i = ComboBoxEdit1.ItemIndex
i += 1
If i > ComboBoxEdit1.ItemCount - 1 Then i = 0
ComboBoxEdit1.ItemIndex = i
Case "CommandButton2" 'Delete control
i = lstCtl.Count
If i < 1 Then Exit Sub
i -= 1
Dim a As Control Ptr = lstCtl.Item(i)
lstCtl.Remove(i)
a->Visible= False
This.Remove a
DeleteControl(a)
Label1.Caption = "Control count: " & lstCtl.Count
Case "CommandButton3" 'Create form
Dim a As Form3Type Ptr
a = New Form3Type
LstFrm.Add a
i = LstFrm.Count
a->Name = "Form" & i
a->Caption = a->Name
a->Show(This)
a->Visible = True
Label2.Caption = "Form count: " & LstFrm.Count
Case "CommandButton4" 'Destroy form
i = LstFrm.Count
If i < 1 Then Exit Sub
Dim a As Form3Type Ptr = LstFrm.Item(i - 1)
LstFrm.Remove i - 1
a->CloseForm
Delete a
Label2.Caption = "Form count: " & LstFrm.Count
Case Else
MsgBox "(" & Sender.Name & ") was clicked."
End Select
End Sub
Private Sub Form3Type.Form_MouseMove(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
If MouseButton <> 0 Then Exit Sub
ReleaseCapture()
SendMessage(Sender.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End Sub
Private Sub Form3Type.CheckBox2_Click(ByRef Sender As CheckBox)
App.DarkMode = Sender.Checked
InvalidateRect(0, NULL, False)
End Sub
Private Sub Form3Type.DeleteControl(ByRef Sender As Control Ptr)
Select Case Sender->Name
Case "CommandButton"
Delete Cast(CommandButton Ptr, Sender)
Case "ComboBoxEdit"
Delete Cast(ComboBoxEdit Ptr, Sender)
Case "CheckBox"
Delete Cast(CheckBox Ptr, Sender)
Case "CheckedListBox"
Delete Cast(CheckedListBox Ptr, Sender)
Case "ImageBox"
Delete Cast(ImageBox Ptr, Sender)
Case "ListControl"
Delete Cast(ListControl Ptr, Sender)
Case "ProgressBar"
Delete Cast(ProgressBar Ptr, Sender)
Case "RadioButton"
Delete Cast(RadioButton Ptr, Sender)
Case "TextBox"
Delete Cast(TextBox Ptr, Sender)
Case "Picture"
Delete Cast(Picture Ptr, Sender)
Case "TrackBar"
Delete Cast(TrackBar Ptr, Sender)
Case Else
'more controls...
End Select
End Sub
Private Sub Form3Type.Form_Destroy(ByRef Sender As Control)
While lstCtl.Count
DeleteControl(lstCtl.Item(0))
lstCtl.Remove(0)
Wend
While LstFrm.Count
Delete Cast(Form3Type Ptr, LstFrm.Item(0))
LstFrm.Remove(0)
Wend
End Sub