I have a screensaver program in VB. It works fine, with no problems. I was wondering if their is a way to make it extend to users with 2 monitors.
Here is the code:
'Escape makes the screensaver exit.
'Spacebar makes the screensaver pause.
Any help would be greatly appreciated. Even any ideas of where to head.
Here is the code:
Code:
Dim rnd As New Random
Dim screenshot As Bitmap
Dim WithEvents timer1 As New Timer
Sub Reset()
x = 0
barAmount = ClientSize.Width / barWidth
Me.Invalidate()
End Sub
Function RandomColor() As Color
Dim c As Color
c = (Color.FromArgb(255, (rnd.Next(0, 255)), (rnd.Next(0, 255)), (rnd.Next(0, 225))))
Return (c)
End Function
Private Sub Screensaver_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Escape
Me.Close()
Case Keys.Space
If timer1.Enabled = True Then
timer1.Enabled = False
Else
timer1.Enabled = True
End If
End Select
End Sub
Private Sub Screensaver_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Dim r As Rectangle = Screen.PrimaryScreen.Bounds
screenshot = New Bitmap(r.Width, r.Height)
Dim g As Graphics = Graphics.FromImage(screenshot)
g.CopyFromScreen(r.X, r.Y, 0, 0, r.Size, CopyPixelOperation.SourceCopy)
Me.BackgroundImage = screenshot
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
Windows.Forms.Cursor.Hide()
barWidth = 50
spacingInt = 0
Reset()
timer1.Interval = 300
timer1.Enabled = True
End Sub
Private Sub Screensaver_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
For i = 1 To barAmount
Dim height1 As Integer = rnd.Next(0, ClientSize.Height)
Dim r As New Rectangle(x, 0, barWidth, height1)
Try
Dim grad As New Drawing2D.LinearGradientBrush(r, (RandomColor()), Color.Transparent, 90, True)
e.Graphics.FillRectangle((grad), r)
Catch ex As Exception
End Try
x += barWidth + spacingInt
Next
End Sub
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick
Reset()
End Sub
End Class
'Spacebar makes the screensaver pause.
Any help would be greatly appreciated. Even any ideas of where to head.