이것은 매우 이상합니다. VS2008에서 잘 작동하는 프로젝트를 이식했지만 VS2017로 빌드하면 한 줄의 존재로 인해 대화 상자의 크기가 조정됩니다. 코드를 실행하지 않아도되고 서브 루틴에 있어야합니다. 운영! 이 동작을 나타낼 수있는 가장 간단한 버전의 프로그램을 만들었습니다. 다른 버전의 Visual Studio에서 제작/실행 해보십시오. 이 문제가 발생하는 이유와 해결 방법에 대한 설명을 모두 좋아합니다. 감사.VS2017에서 대화 상자 크기 변경
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"); }
}
}
}
2012 년과 2017 년에이 코드를 실행하면 어느 버전에서든 양식의 크기가 "크기가 조정되지"않습니다. – LarsTech
죄송합니다. 모든 컴퓨터에서 발생하지는 않지만 매우 자주 발생하는 컴퓨터에서는 일관된 것처럼 보입니다. 한스 패서트 (Hans Passant)의 팁으로이 문제를 해결할 수 있는지 알게 될 것입니다 ... –