KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Analog Clock

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed Jun 20, 2007 11:43 pm    Post subject: Analog Clock Reply with quote

The following script is based on Hong Thang's Analog Clock program written for VB.NET ... what follows are the author's original comments:

Quote:

Hi everybody!
This is a fully functioned analog clock program created on transparent form in VB.NET.
Right click on the clock to see its functions
Thanks for using.


This script requires the latest kf.net posted on June 20th, 2007 (Version 3.2.2):

Code:

Break On

;
; Based on Hong Thang's clock program vb.net.
;

$System = CreateObject("Kixforms.System")

If Not CheckProductVersion($System,3,2,1)
 $= MessageBox("The latest version of Kixforms.Net is not installed. This script will now close.","Kixforms",0)
 Quit
Endif

$Math = $System.Math
$PI = $Math.PI

$HaftSize = 150
$SecondHandLenght = 100
$MinuteHandLenght = 80
$HourHandLenght = 60
$DigitsColor = $System.Color.Red
$MsDown = 0

$Form = $System.Form()
$Form.ClientWidth = 300
$Form.ClientHeight = 300
$Form.FormBorderStyle = $System.FormBorderStyle_None
$Form.BackColor = $System.Color.Brown
$Form.TransparencyKey = $System.Color.Brown
$Form.ShowInTaskBar = 0
$Form.LostFocus = "Form_LostFocus"

$Timer1 = $System.Timer()
$Timer1.Interval = 1000
$Timer1.Enabled = 1
$Timer1.Tick = "Timer1_Tick()"

$ContextMenu = $System.ContextMenu()

$AlwaysOnTopMenu = $ContextMenu.MenuItems.Add($System.MenuItem("Always On &Top"))
$AlwaysOnTopMenu.Checked = 0
$AlwaysOnTopMenu.Click = "AlwaysOnTopMenu_Click()"

$ShowSecondHandMenu = $ContextMenu.MenuItems.Add($System.MenuItem("Show Second-&Hand"))
$ShowSecondHandMenu.Checked = 1
$ShowSecondHandMenu.Click = "ShowSecondHandMenu_Click()"

$LockedMenu = $ContextMenu.MenuItems.Add($System.MenuItem("&Locked"))
$LockedMenu.Checked = 0
$LockedMenu.Click = "LockedMenu_Click()"

$= $ContextMenu.MenuItems.Add($System.MenuItem("-"))

$ExitMenu = $ContextMenu.MenuItems.Add($System.MenuItem("Exit"))
$ExitMenu.Click = "ExitMenu_Click()"

For $i = 0 To 11
 $Label = $Form.Controls.Add($System.Label())
 $Label.FontName = "Times New Roman"
 $Label.FontSize = 32.25
 $Label.FontBold = 1
 $Label.Text = IIF($i,$i,12)
 $Label.Name = "Label" + $Label.Text
 $Label.Height = 53
 $Label.Width = IIF(Len($Label.Text) = 2,59,37)
 $Angle = CDbl($i) * $PI / 6
 $x1 = $Math.Sin($Angle) * ($SecondHandLenght + 20) + $HaftSize
 $y1 = $Math.Cos($Angle + $PI) * ($SecondHandLenght + 20) + $HaftSize
 $Label.Left = $x1 - $Label.Width / 2
 $Label.Top = $y1 - $Label.Height / 2
 $Label.ForeColor = $System.Color.Red
 $Label.BackColor = $System.Color.Brown
 $Label.MouseDown = "Digits_MouseDown()"
 $Label.MouseMove = "Digits_MouseMove()"
 $Label.MouseUp = "Digits_MouseUp()"
 $Label.ContextMenu = $ContextMenu
Next

$Form.Center
$Form.Show

$Timer1.Start
Timer1_Tick()

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function Timer1_Tick()

 Dim $i

 $Form.Refresh() ; Clears Hands

 $Time = Split(@TIME,":")

 $Hour = CDbl($Time[0] Mod 12)
 $Minute = CDbl($Time[1])
 $Second = CDbl($Time[2])

 ; Draws Hour-Hand: 
 $Pen = $System.Pen($DigitsColor, 6)
 $x1 = $Math.Sin(($Hour * 30 + $Minute / 2) * $PI / 180 + $PI) * $HourHandLenght / 5 + $HaftSize
 $y1 = $Math.Cos(($Hour * 30 + $Minute / 2) * $PI / 180) * $HourHandLenght / 5 + $HaftSize
 $x2 = $Math.Sin(($Hour * 30 + $Minute / 2) * $PI / 180) * $HourHandLenght + $HaftSize
 $y2 = $Math.Cos(($Hour * 30 + $Minute / 2) * $PI / 180 + $PI) * $HourHandLenght + $HaftSize     
 $Form.CreateGraphics.DrawLine($Pen, $x1, $y1, $x2, $y2)

 ; Draws Minute-Hand: 
 $Pen = $System.Pen($DigitsColor, 4)
 $x1 = $Math.Sin($Minute * $PI / 30 + $Second * $PI / 1800 + $PI) * $MinuteHandLenght / 5 + $HaftSize
 $y1 = $Math.Cos($Minute * $PI / 30 + $Second * $PI / 1800) * $MinuteHandLenght / 5 + $HaftSize
 $x2 = $Math.Sin($Minute * $PI / 30 + $Second * $PI / 1800) * $MinuteHandLenght + $HaftSize
 $y2 = $Math.Cos($Minute * $PI / 30 + $Second * $PI / 1800 + $PI) * $MinuteHandLenght + $HaftSize
 $Form.CreateGraphics.DrawLine($Pen, $x1, $y1, $x2, $y2)

 ; Draws Second-Hand: 
 If $ShowSecondHandMenu.Checked
  $Pen = $System.Pen($System.Color.Orange, 2)
  $x1 = $Math.Sin($Second * $PI / 30 + $PI) * $SecondHandLenght / 5 + $HaftSize
  $y1 = $Math.Cos($Second * $PI / 30) * $SecondHandLenght / 5 + $HaftSize
  $x2 = $Math.Sin($Second * $PI / 30) * $SecondHandLenght + $HaftSize
  $y2 = $Math.Cos($Second * $PI / 30 + $PI) * $SecondHandLenght + $HaftSize
  $Form.CreateGraphics.DrawLine($Pen, $x1, $y1, $x2, $y2)
 EndIf

EndFunction

Function Digits_MouseDown()
 $e = $System.EventArgs
 If $e.Button = $System.MouseButtons_Left
  $x = $Form.MousePosition.X - $Form.DesktopLocation.X
  $y = $Form.MousePosition.Y - $Form.DesktopLocation.Y
  $MsDown = 1
 EndIf
EndFunction

Function Digits_MouseMove()
 If $MsDown And Not $LockedMenu.Checked
  $Form.SetBounds($Form.MousePosition.X - $x, $Form.MousePosition.Y - $y, $Form.Width, $Form.Height)
 EndIf
EndFunction

Function Digits_MouseUp()
 $MsDown = 0
 Timer1_Tick()
EndFunction

Function Form_LostFocus
 $MsDown = 0
EndFunction

Function ExitMenu_Click()
 $Form.Hide
EndFunction

Function ShowSecondHandMenu_Click()

 $ShowSecondHandMenu.Checked = Not $ShowSecondHandMenu.Checked
 Timer1_Tick()

EndFunction

Function AlwaysOnTopMenu_Click()

 $AlwaysOnTopMenu.Checked = Not $AlwaysOnTopMenu.Checked
 $Form.TopMost = $AlwaysOnTopMenu.Checked

EndFunction

Function LockedMenu_Click()

 $LockedMenu.Checked = Not $LockedMenu.Checked

EndFunction

Function CheckProductVersion($Object,$Major,$Minor,$Build)

 $CheckProductVersion = 1

 If VarType($Object) <> 9
  $CheckProductVersion = 0
  Return
 Endif

 $ProductVersion = $Object.ProductVersion

 If @ERROR
  $CheckProductVersion = 0
  Return
 Endif

 If $ProductVersion.Major < $Major
  $CheckProductVersion = 0
  Return
 Else
  If $ProductVersion.Major = $Major
   If $ProductVersion.Minor < $Minor
    $CheckProductVersion = 0
    Return
   Else
    If $ProductVersion.Minor = $Minor
     If $ProductVersion.Build < $Build
      $CheckProductVersion = 0
      Return
     Endif
    Endif
   Endif
  Endif
 Endif
 
EndFunction
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group