Grasshopper

algorithmic modeling for Rhino

I would like to have a "Settings" component for one of my C# components. I would like to have a win forms pop up when I right-click this component.

Are there any tutorials that would allow you the display a windows form on a Grasshopper canvas?

Thanks!

Views: 953

Replies to This Discussion

Do not display winform controls directly on the canvas, that's almost always a bad idea. The Panel and Slider currently do display TextBoxes, but it's so much code and so many things can go wrong that I wouldn't recommend it. You can display a menu or a form which contains controls, that is the best solution in my opinion.

When you say "C# component", do you mean the C# script component or are you writing components in Visual Studio C#? It is not possible override mouse clicks for C# Script components.

--

David Rutten

david@mcneel.com

The problem with winforms controls on the canvas is that winforms controls don't 'like' to be zoomed. However your image shows you want a Form, so that's fine.

You'll have to make sure that System.Windows.Forms is referenced in your GHA project. Then create a new Form and place your buttons, sliders, checkboxes etc. on it. If you make all these controls public you might not even have to add any code to the form itself.

Instantiate the form from within your component, set the control states based on your local data, show the form as a modal dialog, wait for the OK return code and read all control states back in. From the component it should look a bit like this:

SettingsForm form = new SettingsForm();

form.StartDate.Value = startDate;

form.EndDate.Value = endDate;

form.DateFrequency.SelectedText = "Daily";

etc.

if (form.ShowDialog(Grasshopper.Instances.DocumentEditor) == 

    DialogResult.OK)

{

  startDate = form.StartDate.Value;

  endDate = form.EndDate.Value;

  etc. 

}

--

David Rutten

david@mcneel.com

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service