This is very bizarre. I ported a project that was working fine under VS2008 but when I build it with VS2017, the very presence of one line causes my dialog to resize - the code does not even need to run, it just needs to be present in a subroutine that does run! I have created the simplest version of the program I could come up with to show this behavior. Try building/running under different versions of Visual Studio. I would love both an explanation for why this is happening as well as how to fix it. Thanks.
using System;
using System.IO;
using System.Windows.Forms;
using System.Windows.Media.Imaging; // Need reference to PresentationCore
namespace Test2017
{
    public class MainDlg : Form
    {
        [STAThread]
        static void Main() { Application.Run(new MainDlg()); }
        public MainDlg()
        {
            SuspendLayout();
            var button = new Button { Location = new System.Drawing.Point(7, 56), Size = new System.Drawing.Size(263, 23), Text = "Note size before and after clicking" };
            button.Click += Button_Click;
            ClientSize = new System.Drawing.Size(282, 253);
            Controls.Add(button);
            ResumeLayout(false);
            PerformLayout();
        }
        private void Button_Click(object sender, EventArgs e)
        {
            if (DateTime.Today.Year != 1234) return;    // This will always return
            try
            {
                // The following is never executed - but its very presence causes the dialog to shrink when running under VS2017
                BitmapFrame.Create((FileStream)null);   // Was using this to get metadata - that part works ok
                MessageBox.Show("Success");
            }
            catch { MessageBox.Show("Exception"); }
        }
    }
}
 
    