1

When I was looking for the quickest way to get a GUI based program running on Debian Linux 4.1.x (on the BeagleBone Black), I stumbled upon this thread:

running a NET app in linux in 2015

The platform offering GUI I am most familiar with is .NET, so that seemed like a perfect situation. Now, when I put together a WinForms app in VS2017, even with pretty new .NET 4.7.1, compile it, copy & execute with mono on the Linux target, it does indeed work. I'd be happy, if it weren't for this little spoiler:

If I set the resolution of my main Windows.Forms.Form in Visual Studio to 800x480, which is the native resolution of the TFT display the BeagleBone is supposed to get, for one thing, I noticed that screenshots of that WinForms app's form are only 784x472 instead of 800x480 (on Windows 10), which is already funny enough. But it gets funnier.

First, the setup: The BeagleBone has a FullHD (1920x1080) screen connected to its HDMI port right now, and I configured the resolution to the later target of 800x480, which doesn't look pretty, of course, but the minimalist GUI on there does tell me in the system settings it's really 800x480.

Now the kicker: That program, which gives me nominally too small screenshots in Windows (10), i.e. 16x8 pixels short, actually appears as too wide when executed with Mono on the BeagleBone. And not just a few pixels too wide, more like 1/4 too wide.

Does anybody know why? ...and a solution would be nice also. (Well, make everything less wide in VS until it fits, but that's not a nice solution).

I know that not much work is currently done on Mono WinForms support, but this looks like such a simple problem... that makes it seem not entirely unrealistic that there could be a fix ;)

user1847129
  • 1,010
  • 2
  • 9
  • 21

2 Answers2

2

This can be caused by AutoScaling. You can try disabling it as discribed here:

export MONO_MWF_SCALING=disable
mono myapp.exe

If this fixes it, you can disable it in your application by removing the following line from your form’s designer code:

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

(This line is added automatically by Visual Studio when it creates a new Form. However, if your forms look bad on Linux because of this, they will also look bad on any Windows computer where the default font has been changed.)

OL.
  • 201
  • 3
  • 13
  • Hey, thanks for that hint. It wasn't exactly as described, apparently somewhat outdated, so I guess it'd be incorrect to "accept" your reply, although it's close. See my own reply for how things seem to be now. – user1847129 May 25 '18 at 16:01
1

First off, thanks to "OL.", who got me on the right track. Some things apparently changed, hence my own reply.

So, exporting MONO_MWF_SCALING=disable did absolutely nothing to the situation. But I did not let myself distract by that, and continued to investigate. I did not find AutoScaleBaseSize in a solution wide search. But what was in the designer file, is:

  this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

I commented out the first, and changed the second to: AutoScaleMode.None; So that resulted in a form that at least fit on screen. A bit too small this time. Although in designer it shows .Size to be 800x480, this was not set in the designer file like that. Instead there was:

  this.ClientSize = new System.Drawing.Size(784, 441);

Funny. Maybe Mono's borders or whatever are different. If a certain outer resolution is the goal, it's not the smartest thing to do to set the ClientSize...? I changed that to:

  this.Size = new System.Drawing.Size(800, 480);

Et voila, the size was correct. Now set the form Location to (0,0), and everything is as I wanted it. Well, almost.

The original question / major problem is answered, hence the acceptance. For those who care, I'll describe minor issues I'm still seeing, as comments.

user1847129
  • 1,010
  • 2
  • 9
  • 21
  • The form height is a little smaller than the screen, even if I set the form state to maximized. I set the LXQt taskbar to autohide=true, gets me a little more height, but it still does not fill the screen, which is odd. (4 pixel rows from the bottom form row to the bottom screeen row) – user1847129 May 25 '18 at 16:12
  • Also, the title bar shows no text in Mono. On Windows/.NET, it does. And the bar is gray. No idea whether that's just normal in Mono. – user1847129 May 25 '18 at 16:12
  • And on Mono, the sizing of the child controls on the main form seems to be different. On .NET/Windows, there is a tab control on the main form, it uses the whole size of the form except the usual free border areas the designer will help you include. So to the very last bottom pixel row of the form, were maybe 8 pixels from the TabControl. On Mono, it looked more like it was 3..4 times that much, if not more. And particularly at the bottom, not from the sides or top. – user1847129 May 25 '18 at 16:16
  • Thanks for you detailed explanation! This drove me crazy! – Ksdmg Dec 05 '19 at 15:16
  • 1
    The `AutoScaleMode` trick makes the forms the right size, but the text is still way too large. Any solution? – Mark Jeronimus Jan 12 '21 at 19:50