Modeless Windows form with ilogic

Modeless Windows form with ilogic

wouter
Advocate Advocate
473 Views
3 Replies
Message 1 of 4

Modeless Windows form with ilogic

wouter
Advocate
Advocate

Hi everyone,

 

I created a form with visual studio where certain data is generated automaticly and others must be chosen/filled. It's made based upon a example from KETIV and works great. But i would like to open the form in modeless so we can, for instance measure somethng in inventor and use that value in the form. My problem is that outside of ilogic i can use .show instead of .showdialog but it's not working within ilogic.

This is a part of the code i use to use the form.

Using inputForm As New Data_Form.Form1

                      

'----Data naar form sturen----------------

inputForm.Klantnaam = Klantnaam

                      

'----Form laten zien------------------

Dim formResult As System.Windows.Forms.DialogResult = inputForm.ShowDialog()

                              

'----Data uit form ophalen----------------

Bew0010 = inputForm.WaardeBewerking_0010

              

If formResult = vbOK Then

        dialogResultOK = True

End If

                      

End Using

 

Does anyone know a solutions or another way to do this?  Any tips are appreciated.

Thanks in advance

 

Wouter

0 Likes
474 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor

The easiest way is to add your business logic to the form event FormClose handler. See the sample below.

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

Sub Main
	Dim myForm As New MyCustomForm()
	AddHandler myForm.FormClosed, AddressOf myForm_FormClosed
	myForm.Show()
End Sub

Private Sub myForm_FormClosed(sender As Object, e As FormClosedEventArgs)
	'Add your code after form is closed here

	Dim myForm As MyCustomForm = sender
	MsgBox("Dialog result: " & [Enum].GetName(GetType(DialogResult), myForm.DialogResult) & vbCrLf & "Some text: " & myForm.tbSomeText.Text)

End Sub

Class MyCustomForm
	Inherits Form

	Friend WithEvents btnCancel As Button
	Friend WithEvents tbSomeText As System.Windows.Forms.TextBox
	Friend WithEvents Label1 As Label
	Friend WithEvents btnOK As Button

	Public Sub New()
		InitializeComponent()
	End Sub

	Private Sub InitializeComponent()
		Me.btnOK = New System.Windows.Forms.Button()
		Me.btnCancel = New System.Windows.Forms.Button()
		Me.tbSomeText = New System.Windows.Forms.TextBox()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.SuspendLayout()
		'
		'btnOK
		'
		Me.btnOK.Location = New System.Drawing.Point(116, 226)
		Me.btnOK.Name = "btnOK"
		Me.btnOK.Size = New System.Drawing.Size(75, 23)
		Me.btnOK.TabIndex = 0
		Me.btnOK.Text = "OK"
		Me.btnOK.UseVisualStyleBackColor = True
		'
		'btnCancel
		'
		Me.btnCancel.Location = New System.Drawing.Point(197, 226)
		Me.btnCancel.Name = "btnCancel"
		Me.btnCancel.Size = New System.Drawing.Size(75, 23)
		Me.btnCancel.TabIndex = 1
		Me.btnCancel.Text = "Cancel"
		Me.btnCancel.UseVisualStyleBackColor = True
		'
		'tbSomeText
		'
		Me.tbSomeText.Location = New System.Drawing.Point(113, 12)
		Me.tbSomeText.Name = "tbSomeText"
		Me.tbSomeText.Size = New System.Drawing.Size(159, 20)
		Me.tbSomeText.TabIndex = 2
		'
		'Label1
		'
		Me.Label1.AutoSize = True
		Me.Label1.Location = New System.Drawing.Point(12, 15)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(95, 13)
		Me.Label1.TabIndex = 3
		Me.Label1.Text = "Put some text here"
		'
		'MyForm
		'
		Me.ClientSize = New System.Drawing.Size(284, 261)
		Me.Controls.Add(Me.Label1)
		Me.Controls.Add(Me.tbSomeText)
		Me.Controls.Add(Me.btnCancel)
		Me.Controls.Add(Me.btnOK)
		Me.Name = "MyForm"
		Me.ResumeLayout(False)
		Me.PerformLayout()

	End Sub

	Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
		DialogResult = DialogResult.OK
		Close()
	End Sub

	Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
		DialogResult = DialogResult.Cancel
		Close()
	End Sub
End Class

 

 

0 Likes
Message 3 of 4

wouter
Advocate
Advocate

Finally had some time to look into this.

From what I understand this creates a form via inventor but that would mean i have to completely recreate the existing form or am i missing something?

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

You may need to set the Inventor application window as the Owner of your Windows.Form.Form object, when you show it...and/or put it into a new Inventor.DockableWindow, as its Child.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes