Tuesday, December 23, 2008

How to Moving & Resizing Forms And Controls Through Code

How to Moving & Resizing Forms And Controls Through Code

Create a new Window Application. Here the name of the application is MovingAndResizingFormsAndControls

Set the text property of form1 as MovingAndResizingFormsAndControls

Drag and drop a Button control on your form and set it name BtnMoveAndResize

Set the Text property of the button to Move And Resize as shwn in the Fig.vb-3.36

Double click the BtnMoveAndResize button and add the following code in the code window.

Private Sub BtnMoveAndResize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMoveAndResize.Click
Size = New Size(300, 200)
Location = New Point(0, 0)
BtnMoveAndResize.Size = New Size(60, 80)
BtnMoveAndResize.Location = New Point(20, 20)
End Sub

Dementions can also be set by using the setbounds Method. The argument passed to setBounds Method are as follows

Let us lean how we can resize forms and controls by continuing with the folowing steps:

Drag and drop a Button control and rename BtnsetDimention Then set the Text property Set Dimention

Double click the button control that you have just added to your form and add the following codes in the code window

Private Sub BtnSetDimentions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSetDimentions.Click
SetBounds(10, 10, 400, 300)
BtnSetDimentions.SetBounds(0, 0, 50, 50)
End Sub
End Class

Run the appication by pressing th F5 key.