winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Add `ClickThrough` to `ToolStrip`/`MenuStrip` to bring behavior in-line with other controls.

Open elachlan opened this issue 2 years ago • 9 comments

Background and motivation

There have recently been a couple of issues asking for this feature.

  • #9240
  • #9277

Outline explaining the feature from associated blog post:

ToolStrip classes do not support "Click Through" between forms. For more information on what click through is, I recommend reading https://daringfireball.net/2003/05/interface_details_itunes_vs_safari . In Windows, pretty much all applications use "click through," whereby if you have one window active and click on to another one, the mouse click activates the window and the click is processed by whatever control you had the mouse over.

https://learn.microsoft.com/en-us/archive/blogs/rickbrew/how-to-enable-click-through-for-net-2-0-toolstrip-and-menustrip

API Proposal

public class ToolStrip
{
   public bool ClickThrough { get; set; }

   protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
        if (ClickThrough &&
            m.Msg == NativeConstants.WM_MOUSEACTIVATE &&
            m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT)
        {
            m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
        }

    }
}

API Usage

Enable/Disable the ClickThrough property to change the behavior.

Alternative Designs

default value of property set to false

Risks

If default is true, then behavior could change in existing applications.

Will this feature affect UI controls?

Yes. Toolstrip will allow click through by default or at least allow click through after the developer enables it.

Unsure on accessibility impact.

Feature is not localizable.

elachlan avatar Jun 14 '23 00:06 elachlan

CC: @merriemcgaw

elachlan avatar Jun 14 '23 00:06 elachlan

Based on the blog we should probably also add it for MenuStrip.

elachlan avatar Jun 14 '23 00:06 elachlan

Agreed on the MenuStrip for sure. Based on our current workload it's unlikely that we will get an implementation done before platform shutdown for .NET 8 - once we hit RC1 timeframe we're no longer able to add API Surface area. We've got another month or so, but this isn't the top of the priority stack. If you have an implementation PR you want to push, I can take the API proposal itself to the API review board. Otherwise, we might have to wait to get this in until .NET 9.

merriemcgaw avatar Jun 21 '23 21:06 merriemcgaw

Do you want a PR prior to API review? I am happy to do a PR either way. It seems quite straight forward.

elachlan avatar Jun 21 '23 22:06 elachlan

@elachlan you are the absolute best! Go ahead and put up a PR and we'll review it before the API review so it's a simple matter to get it in.

merriemcgaw avatar Jun 23 '23 00:06 merriemcgaw

@merriemcgaw when is the next API review?

elachlan avatar Jul 04 '23 02:07 elachlan

Sorry for the delay, I was on vacation. I'll talk to the team about this and do the internal review of the API structure on Weds and submit it for official review hopefully this week. I'll keep you posted. Marking as untriaged to make sure it shows up when we talk runtime later this week.

merriemcgaw avatar Jul 10 '23 16:07 merriemcgaw

Sorry for the delay on this one. As a team, we want to take this. Timeline wise however, we are far too close to platform shutdown for .NET 8 and the teams have several very hot irons in the fire. We're going to branch soon for .NET 9, and will get it for the first round of reviews there.

merriemcgaw avatar Jul 12 '23 20:07 merriemcgaw

Understood. Sorry I didn't get it in sooner.

elachlan avatar Jul 12 '23 21:07 elachlan

Reviewed and approved offline.

terrajobst avatar Jul 03 '24 23:07 terrajobst