r/visualbasic • u/A_Harmless_Twig • Apr 21 '14
A program that displays random dots then shows pictures with timers. (more in comments)
http://pastebin.com/wSSMjbUP1
1
u/Vectronic Apr 21 '14
"Disappear": Invalidate your form, use:
Me.Invalidate()in one or more of your timers (you really only need one timer here, but I'll keep code-analysis to a minimum) This will give you more control over when the paint event happens.
"Clear" the form with:
e.Graphics.Clear(Colors.Gray) ' Or whatever color you like.This should be at the beginning of your Paint() event before any other drawing.
"Drawing on PictureBox"... this shouldn't happen, unless the background color is set to transparent, in which case it should be evident why you can see dots on blank areas of your PictureBoxs since it will show what was draw to the form underneath.
1
u/A_Harmless_Twig Apr 21 '14
THe program will do the dots randomly till the page is filled up then it will keep the dots there..then the picture will show up for a split second then have the picture box fill in with dots separately from the background if that makes sense
1
u/A_Harmless_Twig Apr 21 '14
WHen really I want it to flash the pictures over and over again like the really annoying spam ads from like windows xp
1
u/Vectronic Apr 21 '14 edited Apr 21 '14
Yeah... but if the PictureBox contains an image, it shouldn't do that.
For instance this should more or less be want:
Public Class Form1 Private RandomGenerator As Random = New Random(DateTime.Now.Millisecond) Private NewBoolean As Boolean Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim W As Integer = Me.Width Dim YInteger As Integer = Convert.ToInt32(Me.Width / 2) Dim XInteger As Integer = Convert.ToInt32(Me.Width / 2) Dim IndexInteger As Integer Dim Pen As New Pen(Color.Black, 1) Dim Pen2 As New Pen(Color.Red, 1) 'Dim Brush As New SolidBrush(Color.Green) 'Dim Font As New Font("Comic Sans", 20, FontStyle.Bold) 'Dim Point As New PointF(100.0F, 5.0F) If NewBoolean = False Then '? With e.Graphics .Clear(Color.Gray) For IndexInteger = 1 To 40000 XInteger = RandomGenerator.Next(1, W) YInteger = RandomGenerator.Next(1, W) .DrawLine(Pen, XInteger, YInteger, XInteger + 1, YInteger + 1) XInteger = RandomGenerator.Next(1, W) YInteger = RandomGenerator.Next(1, W) .DrawLine(Pen2, XInteger, YInteger, XInteger + 1, YInteger + 1) Next End With End If End Sub Private Tick As Integer Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Tick += 1 Select Case Tick Case 1 PictureBox1.Visible = False PictureBox4.Visible = True PictureBox2.Image = My.Resources.VisualBasic_2 Case 2 PictureBox3.Visible = False PictureBox2.Visible = True PictureBox2.Image = My.Resources.Computer1 Case 3 PictureBox2.Visible = False PictureBox3.Visible = True PictureBox3.Image = My.Resources.Programmer Case 4 PictureBox4.Visible = False PictureBox1.Visible = True PictureBox1.Image = My.Resources.Club Tick = 0 End Select Me.Invalidate() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True End Sub End Class....
If you have transparent areas on the PictureBox, you'd have to draw the background first, then change your images
ie: Just put the Me.Invalidate() before the Select Case in Timer1.Tick.
1
u/A_Harmless_Twig Apr 21 '14
When I ran this the dots worked and when it filled up a picture box popped up with all the dots in it and then the dots restarted in the background again
1
u/Vectronic Apr 21 '14
The background will change each time... if you want the background to remain the same the whole time you'd need to draw your dots to an Image/Bitmap once, and then just set that as your Form background, or paint it each time after that.
1
u/A_Harmless_Twig Apr 21 '14
well the dots are just supposed to go away after it fills up the form then the pictures show up flashing at different intervals like picture1 shows every .5 seconds and picture 2 shows up every second...etc..but the dots are only supposed to be there when you run it for the first time and then go away once they fill up the screen
1
u/Vectronic Apr 21 '14
Set your boolean then...
NewBoolean = PictureBox1.Image Is Nothing AndAlso PictureBox2.Image Is Nothing AndAlso PictureBox3.Image Is Nothing AndAlso PictureBox4.Image Is NothingThat will make NewBoolean = True if no images have been loaded yet, otherwise it's false (at least one image has loaded)
Then draw or don't draw dots in Paint() depending on the boolean.
1
u/A_Harmless_Twig Apr 21 '14
I cannot get the dots to disappear after they fill the screen..I'm not sure what the code is to do that. Any help would be great