How to resize a form using VB.net?

candice

Active member
Joined
Jan 23, 2007
Messages
30
Programming Experience
Beginner
Hi guys:
Here is my idea: When I run the program the form is loaded. And rectangles are drawn on the form.
For example, the code I used in VB6 is like this:
VB.NET:
Private Sub Form_Resize()
Me.Scale (0, 0)-(200, 200)
Me.Cls
Me.Line (20, 20)-(30, 30), vbYellow, BF
Me.CurrentX = 20
Me.CurrentY = 20
Me.Print "CW1"
End Sub
Along with that, I set the windowstate to Maximized.
When the program is run, the form is loaded as Maximized size. And the bottem-right coordinate of the form is always (200, 200). So that if I restore down the form the rectangle will shrink down proportional to the form.
Now I wanna achieve the same goal using VB.net.
VB.NET:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'local scope
        Dim myGraphics As Graphics
        Dim myBrush As New SolidBrush(Color:=Color.Yellow)
        Dim myRectangle As Rectangle
        'return the current form as a drawing surface
        myGraphics = Graphics.FromHwnd(hwnd:=ActiveForm().Handle)
        'create a rectangle object
        myRectangle = New Rectangle(x:=5, y:=5, Width:=20, Height:=20)
        'draw the rectangle to the surface
        myGraphics.DrawRectangle(pen:=New Pen(Color.Black), rect:=myRectangle)
        'fill the rectangle 
        myGraphics.FillRectangle(brush:=myBrush, rect:=myRectangle)
    End Sub
End Class
Along with it I set the windowstate to Maximized too. But how can I resize the form (which means to define the bottom right coordinate) to 200,200? I found that the MaximumSize/MinimumSize properties in the properties column is not what I want.
Could anybody give me a hand? Thank you!
 
Use the Paint event, there you draw through the e.Graphics instance.
 
Back
Top