Comments (9)
@Olina-Zhang can your team please test this?
from winforms.
This didn't actually work in .NET Framework and we've got the work around. @LeafShi1 can your team to do a brief investigation to see if we can identify the cause. Otherwise, since it didn't work in Framework we may not be able to address it in Core.
from winforms.
The documentation of the MessageBox
states then
The form that owns the message box (or the active form) also receives the HelpRequested event.
So, looks like the control flow is following
- the
Control.WmHelp
called for theCustomForm
to handleWM_HELP
- if the active MessageBox context found, then help link opened immediately
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 12009 to 12016 in b0051e3
- even the help link was already opened, the
Control.OnHelpRequested()
is called (as stated by docs, so it is expected)
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 12033 to 12036 in b0051e3
- if the
HelpRequested
event was not handled by the current control (Form
in our example), then theWM_HELP
message is passed for further processing (so, bubbles to the parent). - the
Control.WmHelp()
is called for the parent form, and because the MessageBox is still active, the associatedHelpInfo
is grabbed and the help link opens again. - the interesting moment is that just a presence of the event handler is enough to decide that no bubbling is needed.
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 8097 to 8106 in b0051e3
Conclusion
I can't say for sure if the current behaviour is correct or not. The WM_HELP
bubbling makes sense in non-messagebox cases.
It looks like we can force the MW_HELP
bubbling to stop for the MessageBox
case. This will still be fully compliant with the documentation - the owner form of the MessageBox will get HelpRequested
(as the documentation says), but other/parent forms will not. But this will at least make the HelpRequested
behavior inconsistent in different scenarios.
The other solution might be to introduce an additional state to store information about "this help link has already been processed". But there is the problem that the user can really click the same help button in the same MessageBox multiple times, so it will be absolutely fine to process the same HelpInfo
again.
Workaround
The possible workaround - add the empty HelpRequested
handler for the MessageBox
owner for (the CustomForm
in the test project.
public CustomForm()
{
HelpRequested += (sender, hlpevent) => { };
}
from winforms.
Tested that project in .NET 9.0 and .NET framework 4.8, they have same result: this website "https://github.com/dotnet/winforms/" is opened twice. But if I put the same MessageBox in a button control on form, it is just opened one time.
from winforms.
this is the callstack of MessageBox.Show
I think we are not able to debug Help
button click in Winform
repo.
from winforms.
@Epica3055, the native MessageBox()
is used here. As per docs,
When the user clicks the Help button or presses F1, the system sends a
WM_HELP
message to the owner.
So, you need to track down, where the WM_HELP
is processed and why it is not marked as handled after the first help link opened.
And from the brief code analysis, it is most likely that such a help requests will end somewhere in one of the Help.ShowHelp()
overloads: .
from winforms.
I did some other experiments and found out, that the problem is not related to the UITypeEditor
at all. The problem can be reproduced by simply opening the multiple forms with Form.ShowDialog()
. So, here is a simplified test code.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
using var t = new CustomForm();
t.ShowDialog(this);
}
}
public class CustomForm : Form
{
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
MessageBox.Show(
this,
"Click Help. You will get 2 browsers opened (instead 1 as expected).",
"MessageBox",
MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1,
0,
"https://github.com/dotnet/winforms/");
}
}
I can also confirm, that we have two calls to the Help.ShowHelp()
- the first one from the modal CustomForm
(which is the owner of the MessageBox
) and the second one from the Form1
(which is the owner/parent of the CustomForm
via this Form.ShowDialog()
).
from winforms.
@snechaev , thanks for you information. 👍 I will look into it.
from winforms.
@snechaev thanks you for the analysis ,I add some details here.
Root cause about this issue
When you try to open a MessageBox with a helpFilePath
parameter, and the Window that contains the MessageBox has a parent Window, and click Help
button like this
you will open two web page in browser.
Actually, when there are n ancestor windows, there will be n additional web page in browser.
This happens because:
-
when you click that Help button,
WM_HELP
will be emitted.
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 12918 to 12970 in b0051e3
-
After the event is handled,
WM_HELP
event will also be sent to ancestor window, see the the document here windows/win32/shell/wm-help
and code
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 12007 to 12038 in b0051e3
So the event will be handled multiple times accordingly.
If you want it to be opened one time when you click it once
-
see the code here, line 120307 - 12038.We can see that when
hevent.Handled
is true the event will not be sent to ancestor window.
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 12007 to 12038 in b0051e3
-
See OnHelpRequested method line 8097-8106, We can see that when there is a handler, the
Handled
will be updated totrue
so that the event won't be sent to ancestor Window.
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 8095 to 8115 in b0051e3
workaround
Add a HelpEventHandler
to the window that contains the MessageBox with a helpFilePath
parameter, even if it is empty.
public class CustomForm : Form
{
...
public CustomForm()
{
HelpRequested += (sender, hlpevent) => { };
}
...
}
from winforms.
Related Issues (20)
- [Accessibility] HC themes: toolStripMenuItem is highlighted in unfocused state when its check property is enabled HOT 1
- The DataGridViews overlap after a certain row when they are placed within the FlowLayoutPanel in WinForms HOT 7
- Unstable unit test: System.Windows.Forms.Tests.TextBoxBaseTests.TextBoxBase_Copy_PasteNotEmpty_Success
- Unstable unit test: System.Windows.Forms.Tests.TextBoxBaseTests.TextBoxBase_Undo_CanUndo_Success
- Unstable unit test: System.Windows.Forms.Tests.MenuStripTests.MenuStrip_WndProc_InvokeMouseActivate_Success
- Unstable unit test: System.Windows.Forms.Tests.MenuStripTests.MenuStrip_WndProc_InvokeMouseActivateWithHandle_Success
- Assembly.GetType Throws Exception When Using ControlDesigner in Netcore using Microsoft SDK HOT 4
- Visual Basic Logging configuration via config file broken
- No 8.0.5 or 8.0.6 release? HOT 3
- KeyUp fired many times when RDP session get focus HOT 8
- When the helpNamespace property in helpProvider is blank after delete the previous saved URL, project exit from runtime automatically when press F1 HOT 11
- Introduce Analyzers for correctly guiding the handling of modal dialogs
- [dotnet-sdk-9.0.100-preview.6.24325.8] NotatnikMechanika get System.PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed. HOT 2
- [dotnet-sdk-9.0.100-preview.6.24325.8] paintdotnet get System.NotSupportedException: BinaryFormatter serialization and deserialization have been removed HOT 7
- [dotnet-sdk-9.0.100-preview.6.24325.8] Bulk-Crap-Uninstaller launch failed with error: Exception type : System.PlatformNotSupportedException Message : BinaryFormatter serialization and deserialization have been removed HOT 3
- [dotnet-sdk-9.0.100-preview.6.24325.8] JexusManager get System.PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed. HOT 2
- [dotnet-sdk-9.0.100-preview.6.24325.8] mRemote launch failed with an exception : PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed." HOT 2
- When a ComboBox's data source is bound to an ImmutableArray, its value is reset when it loses focus. HOT 2
- BinaryFormatter error when clicking "Add Tab" command for TabControl in DemoConsole application HOT 2
- Form and controls are not scaled well on HDPI primary monitor when setting custom ApplicationDefaultFont HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winforms.