Well, my first problem is that i would prefer that the background color changes in addition to the drawn shapes over them.
I use the form graphics to draw the shapes and the background color is set by a timer. But every time the timer ticks, the shapes that i drew(via the graphics) are erased.
The next problem that i am having is the actual clock. I have 3 line controls for the hour, minute, and second hands, But as i set their x and y endpoints, the background image(again drawn with the graphics) is erased
I tried the "drawToBitmap" but that didn't seem to work
note: the drawHour code is called after the form is maximized in the form_load event
Code Snippet
Public Sub DrawHour(ByVal t As DateTime, ByVal rect As Rectangle)
'cos = x
'sin = y
Me.DrawToBitmap(image2, Me.Bounds)
h = ((t.Hour * 30) - 90)
Dim radians As Double = h * Math.PI / 180
Dim cos As Double = Math.Cos(radians)
Dim radians1 As Double = h * Math.PI / 180
Dim sin As Double = Math.Sin(radians1)
cos = cos * (rect.Width / 2)
sin = sin * (rect.Width / 2)
Dim graph As Graphics = Me.CreateGraphics
LnHour.X1 = (
Me.Width / 2)
LnHour.Y1 = (
Me.Height / 2)
LnHour.X2 = cos + (
Me.Width / 2)
LnHour.Y2 = sin + (
Me.Height / 2)
Me.BackgroundImage = image2
End Sub
Public Sub DrawClock()
Dim lin As New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), Color.DarkBlue, Color.MediumSpringGreen, 35)
Dim rect As New Rectangle
If Me.Width > Me.Height Then
rect.Width =
Me.Height
rect.Height =
Me.Height
Else : rect.Width = Me.Width
rect.Height =
Me.Width
End If
Dim graph As Graphics = Me.CreateGraphics
rect.X = (
Me.Width / 2) - (rect.Width / 2)
rect.Y = (
Me.Height / 2) - (rect.Height / 2)
'Dim Graph1 As Graphics = pbClock.CreateGraphics
graph.FillRectangle(lin,
New Rectangle(0, 0, Me.Width, Me.Height))
Dim lin2 As New System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Red, Color.Goldenrod, 45)
graph.FillEllipse(lin2, rect)
Dim image01 As Image
image01 =
Me.BackgroundImage
Me.DrawToBitmap(Me.BackgroundImage, Me.Bounds)
'every 30 degrees
'cos = x
'sin = y
Dim pt As New List(Of Point)
n = 30
Do While n <= 360
Dim radians As Double = n * Math.PI / 180
Dim cos As Double = Math.Cos(radians)
Dim radians1 As Double = n * Math.PI / 180
Dim sin As Double = Math.Sin(radians1)
x = cos * ((rect.Width / 2) - 25)
y = sin * ((rect.Width / 2) - 25)
x = x + (
Me.Width / 2)
y = y + (
Me.Height / 2)
n = n + 30
pt.Add(
New Point(x, y))
Loop
Dim txt As New System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.Black, Drawing2D.LinearGradientMode.ForwardDiagonal)
Dim pt1 As New Point
Dim pt2 As New SizeF
Dim ct As Integer = 4
For i = 1 To pt.Count
pt1 = pt.Item(i - 1)
pt2 = (graph.MeasureString(ct,
Me.Font))
pt1.X = pt1.X - (pt2.Width / 2)
pt1.Y = pt1.Y - (pt2.Height / 2)
graph.DrawString(ct,
Me.Font, txt, pt1)
ct = ct + 1
If ct = 13 Then
ct = 1
End If
Next
'pbClock.BringToFront()
image2 =
Me.BackgroundImage
Dim date1 As DateTime = Now
DrawHour(date1, rect)
End Sub