HI
So far I’ve been able to build and install the rhinocommons plugin example but I don’t seem to be able to find the visual designer. I wan’t to add a form with the usual controls like listbox and buttons and textboxes. So far I’ve only been able to add these things programatically but it is very tedious. Can anybody show how to add these things using visual studios built in resources.
HI Dale,
No I don’t know about ETO yet. I am trying to use forms and controls by bringing them at design time. included here is a complete listing of the basic rhino plugin example with my attempts to add a form and a button.
This code works except for it not being able to run again after the first time.
I hope you and others could look it over and give opinions.
thanks
code follows( using vb.net 2013/17 rino5):
Imports System
Imports System.Collections.Generic
Imports Rhino
Imports Rhino.Commands
Imports Rhino.Geometry
Imports Rhino.Input
Imports Rhino.Input.Custom
Imports System.Windows.Forms '**********************
Namespace rp2
<System.Runtime.InteropServices.Guid("7fd2cb16-5f16-4df0-bfbf-ddec24eb93bf")>
Public Class rp2Command
Inherits Command
Dim WithEvents form2 As New Form ' ***************************
Dim WithEvents btnExit As New Button()
Shared _instance As rp2Command
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 rp2Command
Get
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
Get
Return "rp2Command"
End Get
End Property
Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
' TODO: start here modifying the behaviour of your command.
' ---
'********* FORM STUFF *******************************************************
' SET UP A NEW FORM
' Dav create a new form ' from: https://stackoverflow.com/questions/10791898/how-can-i-add-a-new-windows-form-and-then-add-a-picturebox-programmatically
' Dim form2 As New Form ' <--------- error here: type form is not defined.
form2.Size = New System.Drawing.Size(250, 300)
form2.BackColor = Drawing.Color.CadetBlue
form2.Text = "Hello from form 2"
form2.Show()
form2.TopMost = True
' SET UP A EXIT BUTTON
btnExit.Name = "btnExit"
btnExit.Location = New System.Drawing.Point(100, 200)
btnExit.Size = New System.Drawing.Size(100, 25)
btnExit.Text = "EXIT"
btnExit.TabIndex = 1
form2.Controls.Add(btnExit)
' ********* end of form stuff ***********************************************
RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName)
Dim pt0 As Point3d
Using getPointAction As New GetPoint()
getPointAction.SetCommandPrompt("Please select the start point")
If getPointAction.[Get]() <> GetResult.Point Then
RhinoApp.WriteLine("No start point was selected.")
Return getPointAction.CommandResult()
End If
pt0 = getPointAction.Point()
End Using
Dim pt1 As Point3d
Using getPointAction As New GetPoint()
getPointAction.SetCommandPrompt("Please select the end point")
getPointAction.SetBasePoint(pt0, True)
AddHandler getPointAction.DynamicDraw,
Sub(sender, e) e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed)
If getPointAction.[Get]() <> GetResult.Point Then
RhinoApp.WriteLine("No end point was selected.")
Return getPointAction.CommandResult()
End If
pt1 = getPointAction.Point()
End Using
doc.Objects.AddLine(pt0, pt1)
doc.Views.Redraw()
RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName)
'' ---
Return Result.Success
End Function
Private Sub Button_btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' This is the E X I T B U T T O N
' form2.Dispose()
' form2 = Nothing
form2.Close()
' PROBLEM - after closing the form I cant run the plugin again.
' Here is the error information:
' An exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.dll but was not handled in user code
' Additional information: Cannot access a disposed object.
' If there is a handler for this exception, the program may be safely continued.
End Sub
End Class
End Namespace