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

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!

1 Like

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.
2 Likes

thankyou,David,i will try it

%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!

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.

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

As I have observed, the redraw parameter of OnDisplayExpired will re-instantiate the component. Is that correct? If I do OnDisplayExpired(true), an async method in my component seems to terminate. Same with RedrawCanvas.