Grasshopper

algorithmic modeling for Rhino

Can somebody show me a simple code(C#) example for this Radio Button GUI?

I tried to understand Karamba Code with Reflector, but there was too man lines, that I don't need for Radio Button !o!

I need, How can I create Radio Button on GH Component,

and return this values to SolveInstance().

Views: 6297

Attachments:

Replies to This Discussion

"simple code"?

You'll probably need quite a lot of code to get this done. You'll need to create your own attributes and  override three basic methods:

  • Layout()
  • Render()
  • RespondToMouseDown()

The first one makes sure all the shapes are positioned properly. Maybe your object always has the same size in which case it's easy, but it's also possible that the size depends on the size of certain strings you're drawing. Layout is called typically whenever an object is dragged or after its solved.

Render is used to actually display an object on the canvas. It's where you draw all the capsule, it icons, the text, the buttons etc. etc.

RespondToMouseDown() can be overridden so that the user can click on the buttons.

Did you see the 'Custom Attributes' topic in the SDK Help file?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

hi David  have you a simple example of adding the radio button on a component ?

If you just want to add some stuff to a component, that's fairly easy. The hard bit is getting into the middle of a component layout. I attached an attributes class which adds a single button to the bottom of a component:

You'll need to import Grasshopper.GUI, Grasshopper.GUI.Canvas and System.Windows.Forms namespaces.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

thank you david but I want button radio (not Capsule button ) ,

how I can change this ?

:( '

You need to replace the logic that draws one thing with logic that draws another thing. Whether you want to draw a button, a checkbox, a slider, a radio toggle or anything else, the basic idea is outlined in the code I posted.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

yes David I understand these three methods

  • Layout()
  • Render()
  • RespondToMouseDown()

but  how I draw a radio button :( .

How do you want it to look?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I want to draw three simple radio button under the name of the component 

Ok, so what does a "simple radio button" look like? Grasshopper has no radio buttons anywhere so there is no default style for you to adopt. If you want just open or filled circles, then draw circles:

private void DrawRadioButton(Graphics graphics, PointF center, bool checked)

{

  if (checked) {

    graphics.FillEllipse(Brushes.Black, center.X-6, center.Y-6, 12, 12);

  }

  else

  {

    graphics.FillEllipse(Brushes.Black, center.X-6, center.Y-6, 12, 12);

    graphics.FillEllipse(Brushes.White, center.X-4, center.Y-4, 8, 8);

  }

}

You call this method from within the Render() method and you can draw all the empty and filled circles representing all the radio-buttons you want. If you want to add text, then draw a string next to the circles. If you want squares instead of circles, use FillRectangle instead of FillEllipse and so on and so forth.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks for this. Have u switched from vb to c# now?

I've always used both for Grasshopper.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service