algorithmic modeling for Rhino
Oo, textboxes are very difficult. You need a lot of code to make a textbox that responds properly to mouseclicks and keypresses and I don't have the know-how for that.
What you can do is what I do for sliders, scrollers and panels. When the user clicks on some special area, you temporarily display a real textbox on the canvas and then when it loses focus you remove it again. There are some classes in Grasshopper that can help with this, but it's a completely different approach to drawing simple controls on a component.
Another (somewhat easier) solution would be to display a custom window when the user clicks on your component. This window may contain a textbox and any other controls you like.
Where do you want to start?
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Speaking of which, for version 0.9.0050 have you overcome the use of cursor keys whilst in the textbox moving the canvas?
and also the delete button deleting the textbox instead of text?
Ok David I want this : " to display a custom window when the user clicks on your component. This window may contain a textbox and any other controls you like"
-_-
Ok, step one is to make a new System.Windows.Forms.Form. You can use the Visual Studio form designer for this. Then put a bunch of controls onto the form using the toolbox. Textbox, Cancel and OK button for example.
Then you need to override the RespondToMouseDoubleClick method on your custom GH_Attributes class and test to see whether the user double clicked with the left button on a specific region.
If that's the case, create a new instance of your form, populate the textbox, display the form using ShowDialog(Grasshopper.Instances.DocumentEditor) and then wait for the result code.
Here's some sample code that is supposed to go into the RespondToDoubleClick, it assumes that there's a form somewhere with a TextBox called txtTextBox:
Public Overrides Function RespondToMouseDoubleClick(ByVal sender As GH_Canvas, ByVal e As GH_CanvasMouseEvent) As GH_ObjectResponse
If (e.Button = MouseButtons.Left) Then
If (ShowWindowRegion.Contains(e.CanvasLocation)) Then
Dim form As New MyCustomForm()
form.txtTextBox.Text = "Put your current text here"
If (form.ShowDialog(Grasshopper.Instances.DocumentEditor) = DialogResult.OK) Then
Owner.RecordUndoEvent("Text changed")
Owner.TheCustomTextYoureEditing = form.txtTextBox.Text
Owner.ExpireSolution(True)
End If
Return GH_ObjectResponse.Handled
End If
End If
Return MyBase.RespondToMouseDoubleClick(sender, e)
End Function
In the above code, ShowWindowRegion must be a RectangleF that is the current shape of the "Show the window now" button region on your component.
Also do not forget to assign the OK and Cancel buttons the proper DialogResult codes so that when they are clicked the form closes with either DialogResult.OK or DialogResult.Cancel.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
I did the first step (I created a form with text box and ok button) then I tried to test your code to see résulat but there is a problem.
here's my code ://
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by