C# 如何在Winform的调整大小事件中停止循环?
我正在使用Winform。我有一件事。当我调用事件时,它会一次又一次地调用自己。下面是我的代码C# 如何在Winform的调整大小事件中停止循环?,c#,winforms,devexpress-windows-ui,C#,Winforms,Devexpress Windows Ui,我正在使用Winform。我有一件事。当我调用事件时,它会一次又一次地调用自己。下面是我的代码 private void Form1_Resize(object sender, EventArgs e) { int tabHeight = 100; this.Height = tabHeight + 20; this.Top = (Screen.PrimaryScreen.Bounds.Height / 2) - (this.Height / 2); } 事件从t
private void Form1_Resize(object sender, EventArgs e)
{
int tabHeight = 100;
this.Height = tabHeight + 20;
this.Top = (Screen.PrimaryScreen.Bounds.Height / 2) - (this.Height / 2);
}
事件从this.Height=tabHeight+20反复调用自身代码>
我怎样才能停止呼叫循环 这里有一个可能的解决方案:
bool _resizing;
private void Form_Resize(object sender, EventArgs e)
{
if (_resizing) return;
_resizing = true;
int tabHeight = 100;
Height = tabHeight + 20;
Top = (Screen.PrimaryScreen.Bounds.Height / 2) - (Height / 2);
_resizing = false;
}
但是,有一些更好的方法可以只在一个方向上调整窗口的大小: