Grasshopper

algorithmic modeling for Rhino

using "event handler" of "winforms" to "raise an event" in the main class

Hi,

I try to create a grasshopper component using "VisualStudio". when you double click on this component a "Form" will appear. There is a "textbox control" on this form. i want to use this textbox to change the value of all sliders on the canvas. so i need to change the sliders value whenever the "textbox.textchanged" happen.

here are the codes:

SliderControlComponenetAttribiutes:

Public Class SliderControlComponenetAttributes
Inherits Grasshopper.Kernel.Attributes.GH_ComponentAttributes
Public Sub New(ByVal comp As SliderControlComponent)
MyBase.New(comp)
End Sub
Public Overrides Function RespondToMouseDoubleClick(sender As Grasshopper.GUI.Canvas.GH_Canvas, e As Grasshopper.GUI.GH_CanvasMouseEvent) As Grasshopper.GUI.Canvas.GH_ObjectResponse
DirectCast(Me.Owner, SliderControlComponent).DisplayForm()
Return Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled
End Function
End Class

-SliderControlComponenet:

Public Overrides Sub CreateAttributes()
m_attributes = New SliderControlComponenetAttributes(Me)
End Sub
Public Sub DisplayForm()
Dim frm As New Form1
frm.Show()
changeSliders(0.5) 'the value of every slider on the canvas must be changed to 0.5, "just for testing""
Grasshopper.GUI.GH_WindowsFormUtil.CenterFormOnCursor(frm, True)
Me.ExpireSolution(True)
End Sub
Public Sub changeSliders(ByRef newNumber As Double)
Dim ghdoc As GH_Document = OnPingDocument()
Dim obj As IGH_DocumentObject
Dim numberSlider As New Grasshopper.Kernel.Special.GH_NumberSlider
For i As Integer = 0 To ghdoc.ObjectCount
obj = ghdoc.Objects(i)
If TypeOf obj Is Grasshopper.Kernel.Special.GH_NumberSlider Then
MsgBox(obj.NickName) 'the nickname of every slider on the canvas, must be shown, "just for testing"
numberSlider = obj
numberSlider.Slider.Value = newNumber
End If
Next
End Sub
End Class

Up to this point, by double clicking on this component, a form with a textbox wil appear.

Now i want to run changeSlider() subroutine whenever the textbox on this form changes.

I thought it must work if i call it from here:

Public Class Form1

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

'HERE
End Sub
End Class

But i couldn't do that.

Views: 363

Attachments:

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service