Share via

Why does the resolution changes when calling WPF form from windows application form?

PD_Rheem 5 Reputation points
2023-07-12T13:22:21.2033333+00:00

Hello All,

I have a windows form called Form1. There is a button1 on Form1, which opens another form PlotTool, which is a WPF form.

using System;
using System.Windows.Forms;


namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var window = new System.Windows.Window();
            var userControl = new PlotTool.UserControl1();      
            window.Content = userControl;
            window.Show();
        }
    }
}

The WPF code is below

using System.Windows.Controls;

namespace PlotTool
{

    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();

        }

    }
    //code

}

Clicking the button1 changes the resolution and size of the Windows Form1. It can be seen, as in attached picture, that the size of the windows Form1 decreases than original size and it also looks like its resolution has changed. I have tried controlling DPI on forms, but was not helpful.

Why is this happening and how can this be avoided? Hope you can help with this.
I am working in Visual Studio Community 2017 in Windows 10
I have .NET framework 4.6.1

Attached is image for reference.

Thank you.

Developer technologies | Windows Forms
Developer technologies | Windows Presentation Foundation

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.