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


(Andrealu2012) #1

I have read the article from

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#)

(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

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