Switch focus to active viewport

Sorry for the deluge of questions of late. In rhinocommon, is there a way to switch focus from an Eto control to the active viewport?

The issue I’m facing is this: I have a custom button inherited from Drawable (see this class by @curtisw), which prompts the user to select an object in Rhino. Unfortunately, the user has to click in the viewport twice for a selection to register (once to focus on the viewport, and again to select the object). I’d like to get around this by forcing focus onto the viewport, or by making the CustomButton behave like an Eto.Forms.Button, which doesn’t have this issue (see below):

var button = new Button { Text = "Button" };
var custom = new CustomButton { Text = "Custom" };
button.Click += (s, e) =>
{
    GetObject go = new GetObject();
    go.GetMultiple(1, 0); // user can now select object with a single click
};
custom.Click += (s, e) =>
{
    GetObject go = new GetObject();
    go.GetMultiple(1, 0); // user must click twice to select object
};

Any thoughts much appreciated.

Cheers,

Jon

Hi @sarg,

You might try to p/invoke SetFocus, passing it RhinoApp.MainWindowHandle.

– Dale

Thanks for the quick reply, @dale. Unfortunately that doesn’t do it – perhaps because the control is already part of the main window? (It’s in a docked panel.) Any way to shift focus to the viewport specifically?

Not the highest priority issue, but would be nice.

Thanks again,

Jon

Found a decent solution to this: temporarily disabling the button while the event is handled allows focus to kick over to the viewport. Not a bad default behavior anyway.