Friday, October 29, 2010

Friiday, October 29th 2010



Public Class Rectangle

Dim dblLength As Double
Dim dblWidth As Double



Public Function CalculateArea() As Double
Return (dblLength * dblWidth)
End Function

Sub New(ByVal [_length] As Double, ByVal [_width] As Double)
dblLength = _length
dblWidth = _width

End Sub

End Class



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myLength As Double = InputBox("Please enter the length of the box")
Dim myWidth As Double = InputBox("Please enter the width of the box")

Dim myRectangle As New Rectangle(myLength, myWidth)
Me.Label1.Text = "The area is: " & myRectangle.CalculateArea

makeRectangle(myLength, myWidth)


End Sub

Public Sub makeRectangle(ByVal myLength, ByVal myWidth)


Dim firstX, firstY, secondX, secondY As Integer

firstY = 30
firstX = 30
secondY = firstY
secondX = (firstX + myLength) * 2

drawLine(firstX, firstY, secondX, secondY)

firstY = (30 + myWidth) * 2
firstX = 30
secondY = firstY
secondX = (firstX + myLength) * 2

drawLine(firstX, firstY, secondX, secondY)


firstY = 30
firstX = 30
secondY = (firstY + myWidth) * 2
secondX = firstX

drawLine(firstX, firstY, secondX, secondY)

firstY = 30
firstX = (30 + myLength) * 2
secondY = (firstY + myWidth) * 2
secondX = firstX

drawLine(firstX, firstY, secondX, secondY)

End Sub

Private Sub drawLine(ByVal firstX As Integer, ByVal firstY As Integer, ByVal secondX As Integer, ByVal secondY As Integer)
Dim myGraphics As Graphics
Dim myPen As Pen

'’ set the color and the width of the pen
myPen = New Pen(Color:=Color.Blue, Width:=2)

'’ set where the graphics will be drawn
myGraphics = Graphics.FromHwnd(hwnd:=ActiveForm().Handle)

'’ draw the line between two points
myGraphics.DrawLine(pen:=myPen, x1:=firstX, y1:=firstY, x2:=secondX, y2:=secondY)
End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

No comments: