0
我想更改表單的大小(取消激活時)並在激活(重新點擊)時將其重置。重置它,我有全局變量稱爲preferredHeight和preferredWidth,我在MainForm_SizeChanged(這是如果用戶手動調整窗體大小)設置。但是,當我設置新的高度和寬度時,會調用SizeChanged方法!有什麼辦法來區分用戶是否觸發了SizeChanged事件或者我的程序是否做到了?或者,有沒有更好的方法來重置我的表單的大小?謝謝!WPF表格大小已由用戶更改,但未通過程序更改
private void MainForm_SizeChanged(object sender, SizeChangedEventArgs e)
{
preferredHeight = MainForm.Height;
preferredWidth = MainForm.Width;
}
private void MainForm_Deactivated(object sender, EventArgs e)
{
MainGrid.RowDefinitions[3].Height = new GridLength(0);
MainGrid.RowDefinitions[4].Height = new GridLength(0);
MainForm.ResizeMode = ResizeMode.NoResize;
MainForm.Height = 100;
MainForm.Width = 100 * imageWidth/imageHeight;
}
private void MainForm_Activated(object sender, EventArgs e)
{
MainGrid.RowDefinitions[3].Height = new GridLength(1, GridUnitType.Star);
MainGrid.RowDefinitions[4].Height = new GridLength(2, GridUnitType.Star);
MainForm.ResizeMode = ResizeMode.CanResize;
MainForm.Width = preferredWidth;
MainForm.Height = preferredHeight;
}