Control.Resize 事件
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在调整控件大小时发生。
public:
event EventHandler ^ Resize;
C#
public event EventHandler Resize;
C#
public event EventHandler? Resize;
member this.Resize : EventHandler
Public Custom Event Resize As EventHandler
下面的代码示例处理 Resize 的 Form事件。 调整窗体大小时,事件处理程序确保窗体 (保持 Height 正方形,) Width 保持相等。 若要运行此示例,请确保将此事件处理方法与表单的事件 Resize 相关联。
private:
void Form1_Resize( Object^ sender, System::EventArgs^ /*e*/ )
{
Control^ control = dynamic_cast<Control^>(sender);
// Ensure the Form remains square (Height = Width).
if ( control->Size.Height != control->Size.Width )
{
control->Size = System::Drawing::Size( control->Size.Width, control->Size.Width );
}
}
C#
private void Form1_Resize(object sender, System.EventArgs e)
{
Control control = (Control)sender;
// Ensure the Form remains square (Height = Width).
if(control.Size.Height != control.Size.Width)
{
control.Size = new Size(control.Size.Width, control.Size.Width);
}
}
Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Dim myControl As Control
myControl = sender
' Ensure the Form remains square (Height = Width).
If myControl.Size.Height <> myControl.Size.Width Then
myControl.Size = New Size(myControl.Size.Width, myControl.Size.Width)
End If
End Sub
若要确定Size重设大小控件的 ,可以将已注册ControlEventHandler方法的参数强制转换为 sender
,Control并单独) 获取其Size属性 (或 Height 和 Width 属性。
若要处理自定义布局,请使用 Layout 事件而不是 Resize 事件。 事件 Layout 是针对事件 Resize 引发的,也是为了响应影响控件布局的其他更改。
有关处理事件的详细信息,请参阅 处理和引发事件。
产品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |