Control with responsive GUI

(Victormunoz) #1

I have a control with a GUI. But the control is displayed always with the same size.
When the user resizes the widget, it doesn’t react to it, even if I put anchor or resizing functions.
Here is the code I am using:

public MyPlugIn()
Instance = this;

    public static MyPlugIn Instance
        get; private set;

    protected override LoadReturnCode OnLoad(ref string errorMessage)
        Rhino.UI.Panels.RegisterPanel(this, typeof(Forms.MainControl), "Main", Properties.Resources.icon);
        return base.OnLoad(ref errorMessage);

    public void TooglePanel()
        if (Rhino.UI.Panels.IsPanelVisible(Forms.MainControl.GetGUID()))
            Rhino.UI.Panels.OpenPanel(Forms.MainControl.GetGUID(), true);
            var panel = Rhino.UI.Panels.GetPanel<Forms.MainControl>(Rhino.RhinoDoc.ActiveDoc);
            panel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            panel.Resize += Panel_Resize;

    private void Panel_Resize(object sender, System.EventArgs e)
        MessageBox.Show("Control resized");

The resize event never fires, and the anchors don’t seem to change anything.
What should I add in order to make this control responsive?


I have zero experience with Rhino’s forms but you’re putting all the corners anchored, which could cause the problem. The normal thing to do with forms is to put two of them (such as AnchorStyles.Top | AnchorStyles.Left). Try this or wait for better help.

(Victormunoz) #3

But you only set anchors to top and left when you DON’T want a responsive control.
If you want the control to fully adapt its size to its parent’s, then you need to put all four anchors.
Is there any other way you suggest to accomplish it?


That’s not true for windows forms, it doesn’t make sense, if you want something to resize, if you anchor it everywhere how is it going to change? It can be made responsive by leaving the anchors by default, in fact, I think it’s the usual thing to do. Try it!

(Victormunoz) #5

With windows forms, if you anchor a button to the left AND to the right of a form, when you resize the form then the button is also resized, maintaining the distance with the left and right borders.
If you only anchor it to the left, then the button will have always the same size.
I want my control to adapt in the same way when resized. I assumed the anchors would work, but they don’t. So, how can I do it?


It’s the first time I’ve seen this way of doing responsive controls, that’s why I said that this is not true. On the other hand, so I’d be surprised if it was the usual way.
However, if the event resizes does not jump, it must be for another reason, if that object is a form, check the FormBorderStyle property, to make sure it’s a way to resize the form. If not, some property must be preventing it to be resized.


Maybe this will help you

(Victormunoz) #8

I finally found what was missing.
In the load event of my control, I also needed to add there the anchorings.

    private void MainControl_Load(object sender, EventArgs e)
        var panel = Rhino.UI.Panels.GetPanel<Forms.MainControl>(Rhino.RhinoDoc.ActiveDoc);
        panel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
        //panel.Resize += Panel_Resize;  // This is not needed anymore since the anchors do the job