Format - iLogic Custom Made User Form

Format - iLogic Custom Made User Form

a81383
Enthusiast Enthusiast
508 Views
1 Reply
Message 1 of 2

Format - iLogic Custom Made User Form

a81383
Enthusiast
Enthusiast

Good morning,

I'm working on building my first custom windows user form. I found majority of the following code on the forms here at,

https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-external-rule-through-a-button-in...

 

I've been picking away at it for a little while now and feel confident with the code below. But am now looking to start adding text, images, and change various formatting options (such as background color). And I'm not entirely sure where to start. Does anyone have a good resource or class or example code I could look at to begin building the rest of this form? 

 

Thank you for your time!

 

AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Public Class WinForm
	Inherits System.Windows.Forms.Form
	' Declare any thing here that you want to use/access throughout all Subs & Functions
	Public iLogicVb As Autodesk.iLogic.Interfaces.ILowLevelSupport
	Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
	
	Public Sub New() ' Creates the new instance
		oForm = Me
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 500
			.Height = 750
			.TopMost = True
			.Font = oLargerFont
			.Text = "Template"
			.Name = "Template"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "Buttom 1 Test"
			.Top = 25
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click	
		
		Dim oButton2 As New Button()
		With oButton2
			.Text = "Buttom 2 Test"
			.Top = 125
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton2)
		AddHandler oButton2.Click, AddressOf oButton2_Click
		
		Dim oTextBox1 As New TextBox()
		With oTextBox1
			.Text = "I am a Text Box"
			.Top = 225
			.Left = 75
			.Font = oLargerFont
			.Enabled = True
			.Width = 250
			.Height = 50
		End With
		oForm.Controls.Add(oTextBox1)
		AddHandler oTextBox1.Leave, AddressOf oTextBox1_Leave
		
		Dim oCheckBox1 As New CheckBox()
		With oCheckBox1
			.Text = "Check Box"
			.Top = 325
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oCheckBox1)
		AddHandler oCheckBox1.CheckedChanged, AddressOf oCheckBox1_CheckedChanged
		
		Dim oComboBox1 As New ComboBox()
		With oComboBox1
	        .DataSource = {"A", "B", "C", "NA"}
			.Top = 425
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oComboBox1)
		AddHandler oComboBox1.SelectedIndexChanged, AddressOf oComboBox1_SelectedIndexChanged
		
		Dim oRadioButton1 As New RadioButton()
		With oRadioButton1
			.Text = "Radio Button 1"
			.Top = 525
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oRadioButton1)
		AddHandler oRadioButton1.CheckedChanged, AddressOf oRadioButton1_CheckedChanged
		
		Dim oRadioButton2 As New RadioButton()
		With oRadioButton2
			.Text = "Radio Button 2"
			.Top = 575
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oRadioButton2)
		AddHandler oRadioButton2.CheckedChanged, AddressOf oRadioButton2_CheckedChanged
	' This is the end of the main Sub that defines the Form .SelectionChangeCommitted
	End Sub

	Private Sub WinForm_FormClosing(ByVal oSender As Object, ByVal oFormCloseEvents As FormClosingEventArgs) Handles Me.FormClosing
'	    If MsgBox("Are you sure you want to close this Form?",vbYesNo+vbQuestion, "CLOSE") = vbYes Then
'	    Else
'	      oFormCloseEvents.Cancel = True
'	    End If
	 End Sub
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' oSender is a Button
		MsgBox("You just clicked the [" & oSender.Text & "] button.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
'		iLogicVb.RunExternalRule("HML - BetaV017")	
	End Sub
	
	Private Sub oButton2_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' oSender is a Button
		MsgBox("You just clicked the [" & oSender.Text & "] button.",vbOKOnly+vbInformation,"EVENT FEEDBACK")
		'iLogicVb.RunExternalRule("HML Update Tool")		
	End Sub

	Private Sub oTextBox1_Leave(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Text <> oOriginalText Then 'oSender is a TextBox
			MsgBox("The contents of the TextBox have changed.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
		
	Private Sub oCheckBox1_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked = True Then 'Sender is a CheckBox
			MsgBox("You just Checked the [" & oSender.Text & "] checkbox.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
			MsgBox("You just UnChecked the [" & oSender.Text & "] checkbox.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
	
	Private Sub oComboBox1_SelectedIndexChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
'		 oSender is a ComboBox
		MsgBox("You just chose " & oSender.Text & " from the ComboBox.",vbOKOnly+vbInformation,"EVENT FEEDBACK")
	End Sub
	
	Private Sub oRadioButton1_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked Then 'oSender is a RadioButton
			MsgBox("You just changed the Radio Button option to '" & oSender.Text & "'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
'			MsgBox("You just changed the Radio Button option to 'Choice 2'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub

	Private Sub oRadioButton2_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked Then 'oSender is a RadioButton
			MsgBox("You just changed the Radio Button option to '" & oSender.Text & "'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
'			MsgBox("You just changed the Radio Button option to 'Choice 2'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
End Class

'This is the code that actually shows/runs the Form
Public Class RunMyForm
	Private Sub Main
		Dim oMyForm As New WinForm
		oMyForm.Show
	End Sub
End Class

 

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

WCrihfield
Mentor
Mentor

Hi @a81383.  That is likely going to be one of those tasks that you will need to develop over time through research and trial & error testing.  Most of that code looks similar to something I posted on the forums years ago as an example of what is possible from an iLogic rule.  All of those original user submitted KnowledgeBase articles that folks had posted were taken down though.  Designing and creating a really nice Windows Form from within an iLogic rule is pretty challenging, because there are no user interface tools to help you with that task, and very little hints or snippets to even help you get started down that path.  Forms like that are usually created within an external application designed for software development, like Microsoft's Visual Studio, where they have built-in tools to help with that specific task.  Since adding and laying out 'controls' within a Form completely by code, without any user interface helpers was already challenging enough, I did not really explore into customizing colors, or adding images at the time.  Most likely the best place to find help with that task is going to be either within the following Microsoft web address:

https://learn.microsoft.com/en-us/dotnet/api/ 

...and deeper within that area, such as the following links:

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.color 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image 

...then just general internet searches, which I generally begin with the text "vb.net "...then the subject I am searching for.  By the way, when on the Microsoft websites, you may need to change the value of the little drop-down near the top of the pages to "VB", instead of "C#", or "F#", or "C++", in order to see examples in VB, since iLogic uses vb.net as its basis.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes