Bug 15539 - Paint event triggered on Mac OS X while UserControl is not Visible
Summary: Paint event triggered on Mac OS X while UserControl is not Visible
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: 3.2.x
Hardware: Macintosh Mac OS
: Lowest normal
Target Milestone: Community
Assignee: Bugzilla
Depends on:
Reported: 2013-10-21 08:52 UTC by IJsbrand Oudshoorn
Modified: 2017-09-01 11:56 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 15539 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description IJsbrand Oudshoorn 2013-10-21 08:52:24 UTC
Tested on 3.2.0 and 3.2.3.

Some times the Paint event is triggered while running on Mac OS X.

See code below:

        protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
            base.OnPaint (e);

            Control parent = this.Parent;
            while (parent != null)
                if (!parent.Visible)
                    // is only run when using Mono on Mac OS X.
                    Console.WriteLine ("OnPaint: Run while parent is not visible.");
                parent = parent.Parent;

            . . . 
            The real painting code.

The Console.WriteLine is not run when using Mono on Windows or using Microsoft .NET.

The reproduction scenario includes a second form to be loaded, before this issue arise.
 * Form1 has two panels and two buttons.
   - Button1 to switch between panels (bool showPanel1 = !panel1.Visible; panel1.Visible = showPanel1; panel2.Visible = !showPanel1;)
   - Button2 to show Form2 with ShowDialog
 * UserControl with code from above on both panels.
 * Form2 empty

Start program with Form1.
 * Click button 1 to hide panel 1 and show panel 2. 
 * Click button 2 to open Form2 as Dialog.
 * Now it runs Console.WriteLine for every UserControl on the hidden panel1.
 * Close Form2.
 * Now it runs Console.WriteLine again for every UserControl on the hidden panel1.
Comment 1 IJsbrand Oudshoorn 2013-10-21 10:16:59 UTC

I have seen the bug now also happening without using an extra form. But simply by switching to other applications and switching back.

Not sure whether this is related. While testing, on my console I see between the many lines "OnPaint: Run while parent is not visible." I see several lines:

mono[...] <Error>: kCGErrorInvalidConnection: CGSGetWindowTags: Invalid connection

After the first invalid connection line it also prints:

mono[...] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.

For me it is not clear how to get the real error and / or setting the breakpoint.
Comment 2 IJsbrand Oudshoorn 2013-10-22 09:20:35 UTC
Some more information.
For the record, I am running Mac OS X 10.7.5.

I discovered that this behaviour only occurs with implementations of UserControl. Having ordinary Button controls on the panels is working fine.

Secondly, even with the .Visible of the UserControl on false the UserControl is painted.

I will try to make a simple project next month to make the bug reproducible for you.
Comment 3 IJsbrand Oudshoorn 2013-10-23 04:54:10 UTC
This issue might be a duplicate of bug #3124.
Comment 4 Miguel de Icaza [MSFT] 2014-02-12 17:27:02 UTC
Setting priority to lowest, since Windows.Forms is no longer being developed actively.