G
Guest
Dim myGraphics As System.Drawing.Graphics
Dim buffer As Bitmap
Dim fr_bm As Bitmap
Dim to_bm As Bitmap
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
pbxclock.Refresh()
pbxclock.Image.Dispose()
If Not (buffer Is Nothing) Then
buffer.Dispose()
End If
If Not (fr_bm Is Nothing) Then
fr_bm.Dispose()
End If
If Not (to_bm Is Nothing) Then
to_bm.Dispose()
End If
' Get the Bitmaps and a Graphics object
' for the destination Bitmap.
fr_bm = New Bitmap(ImageList1.Images(selectedtheme))
to_bm = New Bitmap(pbxclock.Image)
Dim gr As Graphics = Graphics.FromImage(to_bm)
' Get source and destination rectangles.
Dim fr_rect As New Rectangle(0, 20, 240, 240)
Dim to_rect As New Rectangle(0, -15, 240, 320)
' Draw from the source to the destination.
gr.DrawImage(fr_bm, to_rect, fr_rect, GraphicsUnit.Pixel)
gr.DrawRectangle(New Pen(Color.Transparent), to_rect)
' Display the results.
pbxclock.Image = to_bm
buffer = New Bitmap(pbxclock.Image)
'Dim buffer As New Bitmap(pbxclock.Image)
pbxclock.Image = buffer
Dim cx, cy, rad As Integer
cx = 120 : cy = 120 : rad = 80
myGraphics = Graphics.FromImage(pbxClock.Image)
'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, New Pen(Color.Red), cx, cy, Hour(Now) * 5, rad
* 0.6)
'DrawHand(myGraphics, New Pen(Color.Red), cx - 1, cy - 1, Hour(Now)
* 5, rad * 0.6)
DrawHand(myGraphics, New Pen(Color.Green), cx, cy, Minute(Now), rad
* 0.9)
'DrawHand(myGraphics, New Pen(Color.Green), cx - 1, cy - 1,
Minute(Now), rad * 0.9)
DrawHand(myGraphics, New Pen(Color.Blue), cx, cy, Second(Now), rad)
Label3.Text = "Time: " & Now.ToLongTimeString
Label4.Text = "Date: " & Now.ToShortDateString
'DrawHand(myGraphics, New Pen(Color.Blue), cx - 1, cy - 1,
Second(Now), rad)
myGraphics.Dispose()
End Sub
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 - y)
End SubHi...I am new to VB.NET programming. Please help me to find my
mistakes in my code, because I do not find them: thanky you...juvi
Dim buffer As Bitmap
Dim fr_bm As Bitmap
Dim to_bm As Bitmap
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
pbxclock.Refresh()
pbxclock.Image.Dispose()
If Not (buffer Is Nothing) Then
buffer.Dispose()
End If
If Not (fr_bm Is Nothing) Then
fr_bm.Dispose()
End If
If Not (to_bm Is Nothing) Then
to_bm.Dispose()
End If
' Get the Bitmaps and a Graphics object
' for the destination Bitmap.
fr_bm = New Bitmap(ImageList1.Images(selectedtheme))
to_bm = New Bitmap(pbxclock.Image)
Dim gr As Graphics = Graphics.FromImage(to_bm)
' Get source and destination rectangles.
Dim fr_rect As New Rectangle(0, 20, 240, 240)
Dim to_rect As New Rectangle(0, -15, 240, 320)
' Draw from the source to the destination.
gr.DrawImage(fr_bm, to_rect, fr_rect, GraphicsUnit.Pixel)
gr.DrawRectangle(New Pen(Color.Transparent), to_rect)
' Display the results.
pbxclock.Image = to_bm
buffer = New Bitmap(pbxclock.Image)
'Dim buffer As New Bitmap(pbxclock.Image)
pbxclock.Image = buffer
Dim cx, cy, rad As Integer
cx = 120 : cy = 120 : rad = 80
myGraphics = Graphics.FromImage(pbxClock.Image)
'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, New Pen(Color.Red), cx, cy, Hour(Now) * 5, rad
* 0.6)
'DrawHand(myGraphics, New Pen(Color.Red), cx - 1, cy - 1, Hour(Now)
* 5, rad * 0.6)
DrawHand(myGraphics, New Pen(Color.Green), cx, cy, Minute(Now), rad
* 0.9)
'DrawHand(myGraphics, New Pen(Color.Green), cx - 1, cy - 1,
Minute(Now), rad * 0.9)
DrawHand(myGraphics, New Pen(Color.Blue), cx, cy, Second(Now), rad)
Label3.Text = "Time: " & Now.ToLongTimeString
Label4.Text = "Date: " & Now.ToShortDateString
'DrawHand(myGraphics, New Pen(Color.Blue), cx - 1, cy - 1,
Second(Now), rad)
myGraphics.Dispose()
End Sub
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 - y)
End SubHi...I am new to VB.NET programming. Please help me to find my
mistakes in my code, because I do not find them: thanky you...juvi