1

I'm creating an AddIn for Autodesk Inventor, the AddIn is a simple button in the ribbon.

When the user presses the button a new form is created as dialog.

Private Sub ButtonClick()
        Dim oWindow As New CopyDesignForm(string1, string2)
        oWindow.ShowDialog()
End Sub

The user will then do some operations and a file path as string is the result of his actions. I would now like to return this value so my AddIn can process the file.

But I can't seem to find a good example of this. I can only find an excellent sample of how to pass the ok or cancel result. But not how to get to a variable of the dialog.

Link to ok and cancel result sample

2
  • You can add a string property to the dialog and set the value of the property in your dialog,Then after showing the dialog, check if the dialog result was OK, then read the property. Commented Apr 20, 2016 at 20:35
  • 1
    DialogResult is a Type and you are limited to those defined values. It is intended to signal mainly whether the user canceled the session or made a decision. For other data like a path or whatever, expose it as a property and fetch it if they dont Cancel/No the session Commented Apr 20, 2016 at 20:36

1 Answer 1

2

You can add a string property to the dialog and set the value of the property in your dialog,Then after showing the dialog, check if the dialog result was OK, then read the property.

Code for your customm dialog:

Public Class MyCustomDialog

    Public Property SomeProperty As String

    Private Sub OKCommandButton_Click(sender As Object, e As EventArgs) _
    Handles OKCommandButton.Click

        Me.SomeProperty = "Some Value"
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub CancelCommandButton_Click(sender As Object, e As EventArgs) _
    Handles CancelCommandButton.Click

        Me.SomeProperty = Nothing
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
End Class

Code for your usage of custom dialog:

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim f As New MyCustomDialog
        If (f.ShowDialog() = DialogResult.OK) Then
            MessageBox.Show(f.SomeProperty)
        End If
    End Sub
End Class
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.