Just starting vb.net, return to form after button click function

Hi all, I have just joined the forum and new to vb.Net after years of RhinoScripting.
I’m using SharpDevelop which seems to be similar to Visual Studio, although I’m not sure if the extensions available for VS work with SD?

I have created a form which is opened as soon as the command in entered.

        Dim oForm As ResizeCupboard_Form
        oForm = New ResizeCupboard_Form()

If someone clicks a button it allows them to pick a point in the Rhino Window. It is putting the form behind the Rhino Window while this takes place and I am not able to get it back, return to the form after the GetPoint has been recorded.

Here is the Button code…

Sub Button1Click(sender As Object, e As EventArgs)
	Dim pt_anchor As Rhino.Geometry.Point3d
	        Using getPointAction As New Rhino.Input.Custom.GetPoint()
	            getPointAction.SetCommandPrompt("Pick new Anchor point")
           		If getPointAction.[Get]() <> Rhino.Input.GetResult.Point Then
                	WriteLine("No point selected.") 'was RhinoApp.
                	getPointAction.CommandResult() 'removed Return
            	End If
            	pt_anchor = getPointAction.Point()
	        End Using        
End Sub

I have tried ResizeCupboard_Form.Show(), bring to front, focus, visible… but no success. I can create a New form easily enough, but that doesn’t help either.

I know something needs to go before the End Sub - Can anyone advise how to bring the form back to the front after the button function is completed? oForm is not declared if I reuse it and typing ResizeCupboard_Form.Show() says I have a reference to a non shared member requiring a reference.

Thanks in advance - I have googled and googled to no avail!

I’d be interested to know if there are sample plugins available for vb.net that incorporate forms so I can take a look into how others handle them generally.

Adrian McKenna

Have you tried putting


after End Using in Button1Click?

Thanks for the response. I then get an error that oForm is not declared.
I know I am showing my early learning as that is supposed to be the simple stuff.
If I declare the oForm again in the button function it just create another form rather than going back to the old one.

Here is the full code of the opening section… I’m guessing this oForm object needs to be passed to my button click function.

Thanks again, Adrian!

Imports System
Imports Rhino
Imports Rhino.Commands

Namespace ResizeCupboard

    <System.Runtime.InteropServices.Guid("f4f6afa8-8853-4bcc-8819-2fe23ab6f147")> _
    Public Class ResizeCupboard
        Inherits Command

        Shared _instance As ResizeCupboard

        Public Sub New()
            ' Rhino only creates one instance of each command class defined in a
            ' plug-in, so it is safe to store a refence in a static field.
            _instance = Me
        End Sub

        '''<summary>The only instance of this command.</summary>
        Public Shared ReadOnly Property Instance() As ResizeCupboard
                Return _instance
            End Get
        End Property

        '''<returns>The command name as it appears on the Rhino command line.</returns>
        Public Overrides ReadOnly Property EnglishName() As String
                Return "ResizeCupboard"
            End Get
        End Property

		Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
            ' TODO: complete command.

            Dim oForm As ResizeCupboard_Form
            oForm = New ResizeCupboard_Form()

            Return Result.Success

        End Function
    End Class
End Namespace

Hi Adrian,

Here are a couple of very simple examples that you might find helpful:

Thanks Dale, they were and will be useful.

Using the following code the window will stay in front of the Rhino Window.
If the button I am click is going to GetPoint, what should I do to temporarily hide the form, then bring it back after the GetPoint has been completed?



        Dim oForm As ResizeCupboard_Form
        oForm = New ResizeCupboard_Form()