How to show a window form when double click the component?

unhandled

(Andrealu2012) #1

I have read the article from http://developer.rhino3d.com/guides/grasshopper/extending-the-gui/

but still donnot know how to open a window By double click a component.because i am developing a gh component.
Can you give me a sample code in C# or VB(better C#)
Thankyou!


(David Rutten) #2

There’s quite a lot to this, but these are the major steps required:

  1. Create a new class and derive it from Grasshopper.Kernel.Attributes.GH_ComponentAttributes.
  2. Override the CreateAttributes() method on your GH_Component class, and assign a new instance of your own attributes to the m_attributes class level field.
  3. In your own attributes class, override the RespondToMouseDoubleClick() method, and from there you can create all the windows you want.

(Andrealu2012) #3

thankyou,David,i will try it


(Andrealu2012) #4

%E5%9B%BE%E7%89%87
David,i finish it,thank you for help. and there is another question:
After doubleclick the component,the form shows,and then,i input some number in textbox,then click OK,to change some data in component,but the text on component cannot refresh immediately,only after i move it or click the canvas then the component text refresh…so is there some method to refresh the component immediately?
Thank you!


(David Rutten) #5

OnDisplayExpired can be used to refresh the canvas, but if you also need to update the solution after you close that window (or after you press OK), then you need to call ExpireSolution(true) on the component. That will update both the solution and the canvas.


(Andrealu2012) #6

Thank you David,it works!and i found a reference post,maybe helpful for other people https://discourse.mcneel.com/t/windows-forms-track-bar-live-update-to-grasshopper-component/36731