Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Forms resized after loading WPF

I'm experiencing a strange behavior, one for which I currently do not have an explanation or a solution and I'm hoping someone knows something about this.

So I have a simple Windows Forms application with a single button, which on button click will load a PresentationFramework assembly:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Assembly.Load("PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
    }
}

Now when I have a custom scaling size (for instance 200%) set on my Windows 10 then on a button click the Form will get resized, see the following images.

- BEFORE CLICK:

Form1 before button click

- AFTER CLICK:

Form1 after button click

However this behavior does not occur when I'm using any of the provided scaling options (when I'm not using custom scaling):

Scaling options

I initially thought the problem is related to Form.AutoScaleMode, but it doesn't seem to be. Also I'm unable to observe any changed value in Form object.

like image 536
Kipper Avatar asked Jun 11 '17 10:06

Kipper


1 Answers

I am not sure that I completely understand your issue here but you could try to add the following attribute to your AssemblyInfo.cs file (you'll find it under the Properties node in the Solution Explorer in Visual Studio):

[assembly: System.Windows.Media.DisableDpiAwareness]

This will allow the application to disable to use dots per inch (dpi) awareness for all user interface elements.

like image 95
mm8 Avatar answered Nov 02 '22 23:11

mm8