Color picker from ShowColorDialog() steals focus from Rhino window

Hey there,

I’m working on custom UI elements with Eto and ran into an issue, where Rhino completely loses focus after the default color picker is launched.

Here is how I initiate the dialog:

Rhino.UI.Dialogs.ShowColorDialog(ref activeColor);

The clip below illustrates the issue. Note, how after the color picker dialog is closed no hover effect gets triggered across the UI. Clicking once in the Rhino window brings back the focus.

Is there a way to prevent this behavior?

Hi @mrhe,

Trying calling on of the ShowColorDialog overrides that accepts a parent as a parameter.

Does this help?

– Dale

Thanks for a prompt response, @dale.

What should the parent be set to?

I tried parenting the color picker to my drawable-derived crass, the panel its hosted on, and the ActiveDoc, none of these work. Adding SetFocusToMainWindow() after the color picker is closed doesn’t work either.

var color = new Rhino.Display.Color4f(255);
Rhino.UI.Dialogs.ShowColorDialog(Rhino.RhinoDoc.ActiveDoc, ref color, true);
Rhino.RhinoApp.SetFocusToMainWindow();

EDIT: This happens with all modal dialog boxes, not only the color picker. Modeless work fine. A good example is the About dialog:

Rhino.UI.Dialogs.ShowAboutDialog(true); // modeless -> works without issues
Rhino.UI.Dialogs.ShowAboutDialog(false); // modal -> steals focus

Hey @mrhe, I think you’ll want to use the MainWindowHandle.

var ptr = Rhino.RhinoApp.MainWindowHandle();
Rhino.UI.Dialogs.ShowColorDialog(ptr, ref color, true);

Thanks @csykes, I followed your suggestion but the focus is still lost.
@dale, is this a bug, or am I just using the method in a wrong way?

Hi @mrhe,

I’ll probably need code to a simple example, that I can run here, that reproduces the problem. I’ve not been able to repeat what your reporting - sorry.

– Dale

Hey @dale,

sure thing. Here is a minimal code example to reproduce the issue. I’m using RhinoWindows 7.16.22067.13001

Thanks for spending the time to investigate it!

using System;
using Eto.Forms;
using Eto.Drawing;

namespace UI.Controls
{
    public class ForumTest : Drawable
    {
        private Rectangle rectangle;

        public ForumTest()
        {
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Size = new Size(-1, 20);

            DrawGraphics();

            Parent.SizeChanged -= Parent_SizeChanged;
            Parent.SizeChanged += Parent_SizeChanged;
        }

        private void Parent_SizeChanged(object sender, EventArgs e)
        {
            DrawGraphics();
            Invalidate();
        }

        private void DrawGraphics()
        {
            rectangle = new Rectangle(0, 0, Width, Height);
        }


        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.FillRectangle(Brushes.Red, rectangle);
            base.OnPaint(e);
        }

        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            var color = new Rhino.Display.Color4f(255);
            var ptr = Rhino.RhinoApp.MainWindowHandle();
            Rhino.UI.Dialogs.ShowColorDialog(ptr, ref color, true);

            base.OnMouseDoubleClick(e);
        }
    }
}

Found the issue!

The OnMouseDoubleClick event wasn’t marked as handled. Adding e.Handled = true; returns focus to Rhino.

protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            var color = new Rhino.Display.Color4f(255);
            var ptr = Rhino.RhinoApp.MainWindowHandle();
            Rhino.UI.Dialogs.ShowColorDialog(ptr, ref color, true);

            base.OnMouseDoubleClick(e);
            e.Handled = true;
        }