Results 1 to 3 of 3

Thread: Form Paint Does Not Work

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Form Paint Does Not Work

    Hello! I was working on a screen saver that creates rectangles that start from the center of the screen and expand as they move to the edge of the screen. It was working just fine for a little while, and I'm not sure what I did but now, when I load the form, nothing appears. Can someone please help? Thank you!

    vb Code:
    1. Public Class Form1
    2.  
    3.     Dim R As New Random
    4.     Dim R1 As New Rectangle
    5.     Dim Cs As New Size
    6.     Dim Distance As New Decimal
    7.  
    8.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    9.  
    10.         Me.DoubleBuffered = True
    11.         NewRectangle()
    12.         Timer1.Start()
    13.  
    14.     End Sub
    15.  
    16.     Private Sub NewRectangle()
    17.  
    18.         Distance = 0
    19.         Cs = ClientSize
    20.         R1.Width = R.Next((Cs.Width * 0.1), (Cs.Width * 0.5))
    21.         R1.X = R.Next(-2 * Cs.Width, Cs.Width)
    22.         R1.Height = R.Next((Cs.Height * 0.1), (Cs.Height * 0.5))
    23.         R1.Y = R.Next((Cs.Height * 0.1), (Cs.Height * 0.5))
    24.  
    25.     End Sub
    26.  
    27.     Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
    28.  
    29.         e.Graphics.FillRectangle(Brushes.Blue, New Rectangle((R1.X * Distance + Cs.Width * 0.5), (R1.Y * Distance + Cs.Height * 0.5), (R1.Width * Distance), (R1.Height * Distance)))
    30.  
    31.     End Sub
    32.  
    33.     Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    34.  
    35.         Distance = (Distance + 0.1)
    36.         If Distance > 2 Then
    37.             Distance = 0
    38.             NewRectangle()
    39.         End If
    40.         Me.Invalidate()
    41.  
    42.     End Sub
    43.  
    44. End Class

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: Form Paint Does Not Work

    You're missing the Handles clause:
    Code:
    Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Form1.Paint
    This happens when you cut and paste code.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Form Paint Does Not Work

    Thank you! I actually did cut and paste some code, and I did not realize some of it was changed. Thanks again.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width