Create an instance of a form.

Create an instance of a form.

Anonymous
Not applicable
369 Views
1 Reply
Message 1 of 2

Create an instance of a form.

Anonymous
Not applicable

First off, I'd like to stress that I am not talking about a local form or a global form.

 

I randomly came across this code ages ago and I can't find it for the life of me.

 

Basically my issue is that I need to capture variables local to the ilogic program but I cannot use parameters.  This is so I can export this information with a BOM that goes into a template.

 

Currently I just use a bunch of input boxes but I'm trying to optimize this program that I already have.

 

Any help would be greatly appreciated!

 

Thanks.

0 Likes
370 Views
1 Reply
Reply (1)
Message 2 of 2

Owner2229
Advisor
Advisor

Try this one below. There's an example for using TextBoxes, ComboBoxes, Labels and Buttons. Let me know if you need something else (more).

 

Imports System
AddReference "System.Drawing.dll"
Imports System.Windows.Forms

Sub Main()
	CreateForm("MyForm")
	MF.ShowDialog()
	MsgBox("ComboBox one value: " & CB(0).Text & vbNewLine & "ComboBox two value: " & CB(1).Text & _
	vbNewLine & "TextBox one value: " & TB(0).Text)
End Sub

Private MF As Form
Public CB(0) As ComboBox
Public TB(0) As TextBox

Private Sub CreateForm(Optional Name As String = vbNullString)
	MF = New Form
	MF.Text = Name
	MF.AutoScaleMode = AutoScaleMode.None
	MF.Size = New Drawing.Size(300, 300) 'Width, Heigth
	MF.MinimumSize = MF.Size
	MF.MaximumSize = MF.Size
	MF.Font = New Drawing.Font(MF.Font.FontFamily, 10)
	MF.MaximizeBox = False
	MF.MinimizeBox = False
	MF.ShowIcon = False
	MF.SizeGripStyle = SizeGripStyle.Hide
	MF.StartPosition = FormStartPosition.CenterScreen
	
	AddLabel(5, 5, "Paramter One")
	AddLabel(5, 40, "Paramter Two")
	AddCB(120, 5, {"Option one", "Option two"}, 150)
	AddCB(120, 40, {"Option three", "Option four"}, 150)
	AddTB(120, 75, "SomeText", 150)
	
	AddExitButton()
End Sub

Private Sub AddLabel(PosX As Integer, PosY As Integer, Caption As String, Optional Width As Integer = 100)
	Dim LC As Integer = MF.Controls.Count + 1
	Dim L1 As New Label
	L1.Name = "L" & LC
	L1.Location = New Drawing.Point(PosX, PosY)
	L1.Text = Caption
	L1.Width = Width
	MF.Controls.Add(L1)
End Sub

Private Sub AddTB(PosX As Integer, PosY As Integer, Optional Caption As String = vbNullString, Optional Width As Integer = 100)
	Dim LC As Integer = TB.Length - 1
	If Not TB(LC) Is Nothing Then
		LC = LC + 1
		ReDim Preserve TB(LC)
	End If
	TB(LC) = New TextBox
	TB(LC).Location = New Drawing.Point(PosX, PosY)
	TB(LC).Name = "TB" & LC
	TB(LC).Text = Caption
	TB(LC).Width = Width
	MF.Controls.Add(TB(LC))
End Sub

Private Sub AddCB(PosX As Integer, PosY As Integer, Values() As String, Optional Width As Integer = 100)
	Dim LC As Integer = CB.Length - 1
	If Not CB(LC) Is Nothing Then
		LC = LC + 1
		ReDim Preserve CB(LC)
	End If
	CB(LC) = New ComboBox
	CB(LC).Location = New Drawing.Point(PosX, PosY)
	CB(LC).Name = "CB" & LC
	CB(LC).Width = Width
	For Each Value As String In Values
		CB(LC).Items.Add(Value)
	Next
	MF.Controls.Add(CB(LC))
End Sub

Private Sub AddButton(PosX As Integer, PosY As Integer, Caption As String)
	Dim LC As Integer = MF.Controls.Count + 1
	Dim BT As New Button
	BT.Name = "BT" & LC
	BT.Location = New Drawing.Point(PosX, PosY)
	BT.Text = Caption
	MF.Controls.Add(BT)
End Sub

Private Sub AddExitButton()
	Dim LC As Integer = MF.Controls.Count + 1
	Dim BT As New Button
	BT.Name = "BT_Exit"
	Dim PosX As Integer = MF.Width - (BT.Width * 1.3)
	Dim PosY As Integer = MF.Height - (BT.Height * 3)
	BT.Location = New Drawing.Point(PosX, PosY)
	BT.Text = "OK"
	MF.Controls.Add(BT)
	AddHandler BT.Click, AddressOf Me.ExitButtonClick
End Sub

Private Sub ExitButtonClick()
	MF.Close()
End Sub

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes