cirro1

Hey guys!!!
Can anybody tell me how to draw a simple rectanlge and change the it's color

Would you please write me a code example
It think it isn't that hard but I just couldn't figure out how to do it in VB.

Thanks!



Re: Visual Basic Express Edition drawing a rectanlge

jo0ls

Code Snippet
Public Class Form1

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim rec As New Rectangle(10, 10, Me.ClientSize.Width - 20, Me.ClientSize.Height - 20)
e.Graphics.Clear(Color.Black)
e.Graphics.DrawRectangle(Pens.White, rec)
End Sub

End
Class

http://www.bobpowell.net/beginnersgdi.htm

To alter the color when you click the form:

Code Snippet
Public Class Form1

Private drawRed As Boolean

Private Sub Form1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Click
drawRed =
Not drawRed
Me.Refresh() ' trigger the paint event.
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint
Dim rec As New Rectangle(10, 10, Me.ClientSize.Width - 20, Me.ClientSize.Height - 20)
e.Graphics.Clear(Color.Black)
' clear the background to black
If drawRed Then
e.Graphics.FillRectangle(Brushes.Red, rec)
Else
e.Graphics.FillRectangle(Brushes.Blue, rec)
End If
End Sub

End
Class