DanielVanNoord / System.Windows.Forms

A .Net Core implementation of System.Windows.Forms based on Mono's System.Windows.Forms for Linux and Windows
Other
38 stars 4 forks source link

ContextMenuStrip -> SourceControl property is null #12

Open davidbitterlich opened 3 weeks ago

davidbitterlich commented 3 weeks ago

Hi,

I've been trying to port a WinForms application from dotnet 8 for Windows to Linux. However, I stumbled over an issue in the WinForms implementation (probably directly from Mono but I was unable to check it).

When you build a GUI with a PictureBox and a right-click context menu with atleast one item and a method which is called: if this item is being clicked, it is impossible to get the SourceControl.

The click action method receives a sender object (System.Windows.Forms.ToolStripMenuItem) which has a property Owner that is of type System.Windows.Forms.ContextMenuStrip.

So far this System.Windows.Forms implementation behaves straight like the Windows version, unless you want to get the SourceControl property of this ContextMenuStrip - it is null. On Windows you do get the parent parent control back...

Being able to use a context menu is important for the application that I try to port. I'm not very experienced with Mono WinForms or this version of WinForms. For that reason I cannot provide a solution which could be merged, but I created a demonstrator project which can be used to directly see the issue (the GUI has one big picturebox and a ContextMenuStrip with one element. Clicking this element will open a MessageBox with either the underlying control or no underlying control message)

ContextMenuSourceControlExample.zip

sancheolz commented 2 weeks ago

Try sending a bug report to https://bugs.winehq.org/describecomponents.cgi?product=Mono. Mono was reincarnated in https://gitlab.winehq.org/wine-mono/mono and there is some activity there.

davidbitterlich commented 2 weeks ago

Not sure about this. I've set up an Ubuntu VM for running Mono and there it seems to work... the same codebase (well, downgraded a bit as the old C# syntax did not support recursive pattern... and voilà, it works there:

Bildschirmfoto 2024-07-02 um 15 43 39

So I think the problem might be caused by any changes during the porting process of System.Windows.Forms from Mono to dotnet.

sancheolz commented 2 weeks ago

This repository was synced with main branch of mono, but version of mono in yours Ubuntu VM is 6.12 maybe(what says mono -V command?). So codebase can be much differ.

davidbitterlich commented 2 weeks ago

Indeed, the version installed in the Ubuntu VM (which came directly from Mono's repository) is 6.12.0.200. When was the last sync of this repository with main branch? The version output of mono indicates that it was built on 11th of July 2023.

I just built Mono based the Wine Mono version from gitlab (6.13.0) and the error indeed appears here.

Bildschirmfoto 2024-07-02 um 17 39 19

I'm going to open a bug report to their BugZilla tracker. We should however keep this issue open - atleast to track that there is an issue which will eventually be fixed upstream and then synced back to this project...

davidbitterlich commented 2 weeks ago

For reference, I've created the bug report at Wine's BugZilla: https://bugs.winehq.org/show_bug.cgi?id=56911

sancheolz commented 2 weeks ago

The 6.12 version's branch was split from the main branch in 2020 in February. Winforms changes were not backported into it from main. There have been no commits in the Winforms namespace since 2022. So you need to look for the problem between the creation of the 2020-02 branch and the latest change for Winforms.

davidbitterlich commented 2 weeks ago

Alright, I think the guilty commit in Mono was https://gitlab.winehq.org/wine-mono/mono/-/commit/60da71f05fa149dc6402c967256dcac0a3f81c21 (60da71f0). Ive spent some hours to checkout different commits, rebuild mono and test against my demonstrator app and when I build Mono with this commit, it starts to have the issue here...