Control.Resize Event
Occurs when the control is resized.
[Visual Basic] Public Event Resize As EventHandler [C#] public event EventHandler Resize; [C++] public: __event EventHandler* Resize;
[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.
Event Data
The event handler receives an argument of type EventArgs.
Remarks
To determine the Size of the resized control, you can cast the sender parameter of the EventArgs data to a Control object and get its Size property (or Height and Width properties individually).
To handle custom layouts, use the Layout event instead of the Resize event. The Layout event is raised in response to a Resize event, but also in response to other changes that affect the layout of the control.
For more information about handling events, see Consuming Events.
Example
[Visual Basic, C#, C++] The following example handles the Resize event of a Form. When the form is resized, the event handler ensures that the form stays square (its Height and Width remain equal).
[Visual Basic] 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 [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); } } [C++] 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); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
Control Class | Control Members | System.Windows.Forms Namespace | OnResize | Size | Layout