Private myBrush As System.Drawing.SolidBrush Private formGraphics As System.Drawing.Graphics Private p2vbW As Integer Private p2vbH As Integer Private p2vbX1 As Integer Private p2vbY1 As Integer Private p2vbX2 As Integer Private p2vbY2 As Integer Private myPen as Pen ' Make a choice of colors via mouse clicks in Rectangles -- ' A demonstration of Boolean operators and Boolean functions. ' from graphics import * Public Function isBetween(x As Object, end1 As Object, end2 As Object) ' Return True if x is between the ends or equal to either. ' The ends do not need to be in increasing order. Return end1 <= x <= end2 or end2 <= x <= end1 End Function Public Function isInside(point As Object, rect As Object) ' Return True if the point is inside the Rectangle rect. Dim pt1 As Object pt1 = rect.getP1() Dim pt2 As Object pt2 = rect.getP2() Return isBetween(point.getX(), pt1.getX(), pt2.getX()) and isBetween(point.getY(), pt1.getY(), pt2.getY()) End Function Public Function makeColoredRect(corner As Point, width As Integer, height As Integer, color As String, win As Object) ' Return a Rectangle drawn in win with the upper left corner ' and color specified. Dim corner2 As Point corner2 = corner corner2.X = corner2.X + width corner2.Y = corner2.Y + -height Dim rect As Rectangle rect = New Rectangle(corner, corner2) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.FromName(color)) formGraphics = Form1.CreateGraphics() formGraphics.FillRectangle(myBrush, rect) Return rect End Function Public Sub main() Dim winWidth As Integer winWidth = 400 Dim winHeight As Integer winHeight = 400 Form1.Text = "pick Colors" Form1.Width = winWidth + 100 p2vbW = winWidth Form1.Height = winHeight + 100 p2vbH = winHeight p2vbX1 = 0 p2vbY1 = 0 p2vbX2 = winWidth p2vbY2 = winHeight ' right side up coordinates Dim redButton As Integer Dim win As Object redButton = makeColoredRect(New Point(310, 350), 80, 30, "red", win) Dim yellowButton As Integer yellowButton = makeColoredRect(New Point(310, 310), 80, 30, "yellow", win) Dim blueButton As Integer blueButton = makeColoredRect(New Point(310, 270), 80, 30, "blue", win) Dim house As Rectangle house = makeColoredRect(New Point(60, 200), 180, 150, "gray", win) Dim door As Rectangle door = makeColoredRect(New Point(90, 150), 40, 100, "white", win) Dim roof As Point() = {New Point(50, 200), New Point(250, 200), New Point(150, 300)} myPen = New Pen(Drawing.Color.Black, 1) formGraphics.DrawPolygon(myPen, roof) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.black) formGraphics.FillPolygon(myBrush, roof) Dim msg As New Label msg.Left = p2vbW * ((winWidth/2) / (p2vbX2 - p2vbX1)) msg.Top = p2vbH - (p2vbH * (( 375) / (p2vbY2 - p2vbY1))) msg.Text = "Click to choose a house color." msg.AutoSize = True Form1.Controls.Add(msg) Dim pt As Object Dim color As String if isInside(pt, redButton) Then color = "red" ElseIf isInside(pt, yellowButton) Then color = "yellow" ElseIf isInside(pt, blueButton) Then color = "blue" else color = "white" End If msg.Text = "Click to choose a door color." if isInside(pt, redButton) Then color = "red" ElseIf isInside(pt, yellowButton) Then color = "yellow" ElseIf isInside(pt, blueButton) Then color = "blue" else color = "white" End If msg.Text = "Click anywhere to quit." End Sub 'main()