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.

How to print Dialog

How to print Dialog

Create a new Windows application Form Here the name of the application is (Print Dialog )
Set the Text property of form1 as Print Dialog

Drag & Drop One Button Control, one PrinterDialog Control.and PrintDocument object from the Toolbox
Set the Name property of the button as BtnPrint the Text property as Print

Now, after setting the control property, Double Click on the print button and add the following code

Private Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
PrintDialog1.Document = PrintDocument1
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages = True

If PrintDialog1.ShowDialog =Windows.Forms.DialogResult.OK Then
PrintDocument1.PrinterSettings = _PrintDocument1.PrinterSettings
PrintDocument1.Print()
End If
End Sub

Private Sub docprinting(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
Dim str As String = "The quick brown dog Jumped over the lazy Fox."
Dim prnfont As New System.Drawing.Font _
("Arialr", 25, System.Drawing.FontStyle.Regular)
e.Graphics.DrawString(str, prnfont, System.Drawing.Brushes.Black, 20, 7)

End Sub
End Class


Press F5 key from the keyboad to run the applicatin
Click the print Button to print the Document