dotnet / dotnet/winforms

TaskDialogPage F1 help bubbles up to owner control

Open
#11,135 5 comments 0 reactions 1 assignee Claimed by @JeremyKuhne View on GitHub
:beetle: bug
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .NET version

8.0.202

### Did it work in .NET Framework?

No

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

_No response_

### Issue description

When a TaskDialog is open and the user presses F1, the TaskDialogPage.HelpRequest event is first raised, as expected. After the event handler returns, the help request unexpectedly propagates to the owner control of the TaskDialog, and the Control.HelpRequested event is also raised. This second event should be suppressed somehow.

### Steps to reproduce

TaskDialogHelp.csproj:

```XML


WinExe
net8.0-windows
enable
true

```

Program.cs:

```csharp
namespace TaskDialogHelp;

using System;
using System.Drawing;
using System.Windows.Forms;

internal static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
private static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}

internal sealed class Form1 : Form
{
internal Form1()
{
var button = new Button()
{
Dock = DockStyle.Fill,
Text = "Show TaskDialog",
};
button.Click += this.ButtonClick;
this.Controls.Add(button);
}

private void ButtonClick(object? sender, EventArgs e)
{
var page = new TaskDialogPage()
{
AllowCancel = true,
Text = "Press F1 for help",
};
page.HelpRequest += this.TaskDialogPageHelpRequest;
TaskDialog.ShowDialog(this, page, TaskDialogStartupLocation.CenterOwner);
}

private void TaskDialogPageHelpRequest(object? sender, EventArgs e)
{
MessageBox.Show("TaskDialogPage.HelpRequest");
}

protected override void OnHelpRequested(HelpEventArgs e)
{
if (!e.Handled)
{
MessageBox.Show("Control.HelpRequested");
e.Handled = true;
}

base.OnHelpRequested(e);
}
}
```

1. Build and run the program. `dotnet run`
2. A form opens. Click the "Show TaskDialog" button.
3. A TaskDialog opens. Press the F1 key.
4. A message box "TaskDialogPage.HelpRequest" opens. Click the "OK" button.
5. A message box "Control.HelpRequested" opens. That should not happen.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.