I developed a Windows Forms dialog that should be reused in other applications, WPF and Windows Forms. This works fine when I use it in a Windows Forms application, but it causes some layout problems when called in a WPF application. The sizes and sizes are inconsistent when measured from pixels on the screen, from what WinForms API says, and from Spy ++. The window is 10 pixels wider and taller when run without a debugger than Spy ++ says it is, and I say it should be. What is the problem? I cannot find anything, but I will say that this is a very broken .NET Framework.
Here is the form class code:
using System; using System.Drawing; using System.Windows.Forms; namespace DialogTestApp { internal class MyDialog : Form { public MyDialog() { Text = "Title"; Width = 500;
Just put this file in an empty WPF application project and call it from the application constructor:
public MainWindow() { InitializeComponent(); new MyDialog().ShowDialog(); Application.Current.Shutdown(); }
Here's what it looks like with a debugger:

And without:

An extra pink frame is 10 pixels that shouldn't be there. The green label is configured to fill the entire space.
source share