D
double-helix
Guest
Lo People.
Well, whats new? Well being the nice person I am, i only just realized the amazing potential of the system.drawing.graphics class. So, being the .NET addict i am, i came up with this analog clock. Be warned, your system will have to be running in AM / PM time, not 24hr for this to work.
So, start a new project in Visual Basic, and choose A Windows Application. Create A picturebox, and change the name of it to pbxClock. Then, create a timer control, and leave it as timer1, changing the interval to 1000. Also, make sure the timer is enabled.
right - now go into the code view, and type the following:
Sub DrawHand(ByVal myGraphics as Graphics, ByVal myPen as Pen, ByVal cx as Integer, ByVal cy as Integer, ByVal num as Integer, ByVal rad as Integer)
dim x, y as Integer
x = rad * Math.Sin((num * Math.PI) / 30)
y = rad * Math.Cos((num * Math.PI) / 30)
myGraphics.drawLine(myPen, cx, cy, cx + x, cy - y0
End Sub
Note, this next code goes into the tick of the timer control
Sub Timer1_Tick()
dim cx, cy, rad as Integer
cx = 100 : cy = 100 : rad - 80
dim myGraphics as system.drawing.Graphics
myGraphics = pbxClock.CreateGraphics()
myGraphics.FillEllipse(Brushes.white, cx - rad, cy - rad, rad * 2, rad * 2)
myGraphics.DrawEllipse(Pens.yellow, cx - rad, cy - rad, rad * 2, rad * 2)
DrawHand(myGraphics, Pens.red, cx, cy, Hour(Now) * 5, rad * 0.6)
DrawHand(myGraphics, Pens.green, cx, cy, Minute(Now), rad * 0.9)
DrawHand(myGraphics, Pens.blue, cx, cy, Second(Now), rad)
myGraphics.dispose()
End Sub
Thats All Folks
And so, you see how simpleit is to create advanced graphics.
Later people. Email @ irish_kneecaps@hotmail.com
Well, whats new? Well being the nice person I am, i only just realized the amazing potential of the system.drawing.graphics class. So, being the .NET addict i am, i came up with this analog clock. Be warned, your system will have to be running in AM / PM time, not 24hr for this to work.
So, start a new project in Visual Basic, and choose A Windows Application. Create A picturebox, and change the name of it to pbxClock. Then, create a timer control, and leave it as timer1, changing the interval to 1000. Also, make sure the timer is enabled.
right - now go into the code view, and type the following:
Sub DrawHand(ByVal myGraphics as Graphics, ByVal myPen as Pen, ByVal cx as Integer, ByVal cy as Integer, ByVal num as Integer, ByVal rad as Integer)
dim x, y as Integer
x = rad * Math.Sin((num * Math.PI) / 30)
y = rad * Math.Cos((num * Math.PI) / 30)
myGraphics.drawLine(myPen, cx, cy, cx + x, cy - y0
End Sub
Note, this next code goes into the tick of the timer control
Sub Timer1_Tick()
dim cx, cy, rad as Integer
cx = 100 : cy = 100 : rad - 80
dim myGraphics as system.drawing.Graphics
myGraphics = pbxClock.CreateGraphics()
myGraphics.FillEllipse(Brushes.white, cx - rad, cy - rad, rad * 2, rad * 2)
myGraphics.DrawEllipse(Pens.yellow, cx - rad, cy - rad, rad * 2, rad * 2)
DrawHand(myGraphics, Pens.red, cx, cy, Hour(Now) * 5, rad * 0.6)
DrawHand(myGraphics, Pens.green, cx, cy, Minute(Now), rad * 0.9)
DrawHand(myGraphics, Pens.blue, cx, cy, Second(Now), rad)
myGraphics.dispose()
End Sub
Thats All Folks
And so, you see how simpleit is to create advanced graphics.
Later people. Email @ irish_kneecaps@hotmail.com