[Mono-winforms-list] Paint event triggered on Mac OS X while parent is not Visible
IJsbrand Oudshoorn
oudshoorn at eitri.nl
Fri Oct 18 15:47:02 UTC 2013
Hi all,
I am new to this list, but read most of the recent threads. I hope someone can point me to the code in mono where is decided which control is drawn.
First some details:
Mono version: 3.2.0
Architecture: x86
About This Mac: Mac OS X, Version 10.7.5 (Lion)
I am trying to port a Windows.Forms application to Mac OS X.
Running our application on Mono on Windows is working great, no problem at all.
Running the application on Wine on Mac is working as well, but performs very badly.
Running the application on Mono on Mac OS X is working on normal speed, but unfortunately has some drawing issues.
Controls are drawn while the panel where they are on is not visible.
I read a lot about "advice" of not using Windows.Forms on Mac OS X, but since more than 99% of the GUI is working, I think this last 1% is fixable as well.
While debugging a lot of the code I found the cause of my problems: the code in my override void OnPaint is run when running on Mac OS X.
To make this clear I added a check on Parent.Visible, see code snippet below.
The Console.WriteLine code is NOT run when using Microsoft .Net, NOT when using Mono on Windows, BUT it is run when using Mono on Mac OS X.
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.");
return;
}
parent = parent.Parent;
}
. . .
The real painting code.
}
So I dived into the mono code. But since it is a very large code base, it is a bit hard to find my way.
As far as I can see DrawToBitmap in Control.cs in the managed.Windows.Forms project is responsible for drawing the controls.
But I cannot find where it is called. So I can may be nail down the source where the Mac implementation decides to invoke DrawToBitmap while it shouldn't.
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.
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.
As said above, I hope someone can point me to the right direction.
So far I could find, no bug like this is reported yet, but I am not sure. Is this a known bug to one of you?
Thanks a lot for reading (if you came so far J )
IJsbrand
PS: Jay Ge, sorry can't help you. I have no experience with Mono on Linux. I have seen status=InvalidParameter on Mac when using X11 when it could not find the correct library files.
Urios | Westerweg 155 | 1815 JJ Alkmaar | The Netherlands
phone +31 72 5122205 | info at urios.nl | www.urios.nl
bic ABNA NL2A | iban NL46 ABNA 0503003999
kvk 51645866 | vat id NL 8501.10.233.B.01
Urios is a trade name of Eitri B.V.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20131018/13c3c780/attachment.html>
More information about the Mono-winforms-list
mailing list