Grasshopper

algorithmic modeling for Rhino

Hi,

I am making a custom button and it is working as designed except for one issue. When the button (called MaxButton) is overlaid on top of other components, the circle in the button is drawn on top of them, but the 'base' is beneath. This is shown in the image below with the button both above and below the C# component.

The render method in my custom ButtonAttribute class (which is a subclass of ResizableAttributes) is as follows:

protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics,
            Grasshopper.GUI.Canvas.GH_CanvasChannel channel)
        {
            base.Render(canvas, graphics, channel);
            RenderButton(canvas,graphics);
        }

It calls an additional method that renders the inner Circle:



protected void RenderButton(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics)
        {
            SolidBrush brush;
            if (!((MaxButton)this.Owner).ButtonDown)   
                brush = new SolidBrush(((MaxButton)this.Owner).ButtonUpColour);
            else
                brush = new SolidBrush(((MaxButton)this.Owner).ButtonPressColour);
            graphics.FillEllipse((Brush)brush, this.CircleBounds);
            brush.Dispose();
            Pen pen = new Pen(((MaxButton)this.Owner).BorderColour, 4);
            graphics.DrawEllipse(pen, this.CircleBounds);
            pen.Dispose();
        }

Any help is greatly welcome. Thanks in advance!

Views: 380

Replies to This Discussion

Please only draw your stuff in the Objects channel. The Render method is called a number of times, each time with a different channel. Typically you only have to draw things in the Wire and the Object channels.

--

David Rutten

david@mcneel.com

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service