• 0

[VB.NET] Docking manual code


Question

Hello,

I have the code that producing manual clock but i have no idea how to locate it actually how to dock it to the right/left side of my form no matter is form maximized or not ... i will apreciate any help .... thanks in advance

Below is code i use for clock:

Const kordinataX = 600
    Const kordinataY = 100
    Const SecondHandLenght = 60
    Const MinuteHandLenght = 50
    Const HourHandLenght = 40
    Dim l As Label
    Dim Pen As New Drawing.Pen(System.Drawing.Color.Red, 2)
    Dim Second, Minute, Hour As Integer
    Dim x1, y1, x2, y2 As Integer
'
'here is the timer Sub
'
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Refresh() ' Clears Hands

        Second = Microsoft.VisualBasic.DateAndTime.Second(Now)
        Minute = Microsoft.VisualBasic.DateAndTime.Minute(Now)
        Hour = Microsoft.VisualBasic.DateAndTime.Hour(Now)

        ' Draws Hour-Hand:  
        Pen = New Drawing.Pen(System.Drawing.Color.MediumSeaGreen, 4)
        x1 = Sin(((Hour Mod 12) * 30 + Minute / 2) * PI / 180 + PI) * HourHandLenght / 5 + kordinataX 'Tail x
        y1 = Cos(((Hour Mod 12) * 30 + Minute / 2) * PI / 180) * HourHandLenght / 5 + kordinataY 'Tail y
        x2 = Sin(((Hour Mod 12) * 30 + Minute / 2) * PI / 180) * HourHandLenght + kordinataX 'Head x
        y2 = Cos(((Hour Mod 12) * 30 + Minute / 2) * PI / 180 + PI) * HourHandLenght + kordinataY 'Head y
        Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)

        ' Draws Minute-Hand:  
        Pen = New Drawing.Pen(System.Drawing.Color.MediumSeaGreen, 3)
        x1 = Sin(Minute * PI / 30 + Second * PI / 1800 + PI) * MinuteHandLenght / 5 + kordinataX
        y1 = Cos(Minute * PI / 30 + Second * PI / 1800) * MinuteHandLenght / 5 + kordinataY
        x2 = Sin(Minute * PI / 30 + Second * PI / 1800) * MinuteHandLenght + kordinataX
        y2 = Cos(Minute * PI / 30 + Second * PI / 1800 + PI) * MinuteHandLenght + kordinataY
        Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)

        ' Draws Second-Hand:  
        Pen = New Drawing.Pen(System.Drawing.Color.DimGray, 2)
        x1 = Sin(Second * PI / 30 + PI) * SecondHandLenght / 5 + kordinataX
        y1 = Cos(Second * PI / 30) * SecondHandLenght / 5 + kordinataY
        x2 = Sin(Second * PI / 30) * SecondHandLenght + kordinataX
        y2 = Cos(Second * PI / 30 + PI) * SecondHandLenght + kordinataY
        Me.CreateGraphics.DrawLine(Pen, x1, y1, x2, y2)
    End Sub

Note: Do i need maybe check user's screen resolution so regard to resolution make the code eg. (i just improvise) if resolution is 1024 x 768 Then kordinataX = 900 'or this is bad idea ... :cry:

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I did a similar thing. I have a clock made from a label that I always want to be on the right side. What I did was check the screen resolution, then minus off a number from the left propertey of the label I used...

Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
 lblclock.Left = intX - 128

Link to comment
Share on other sites

  • 0
I did a similar thing. I have a clock made from a label that I always want to be on the right side. What I did was check the screen resolution, then minus off a number from the left propertey of the label I used...

Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
 lblclock.Left = intX - 128

584808235[/snapback]

How things are simply if you know the way ... lol

Thanks ... i almost resolved my issue but (always "but" :) ) it works only with maximized form and when my form is by default i.e. 760 x 560 it's unvisible actually its coordinates are so far to be seen .... means i need to check is form maximized or not .. i guess

Little asking ... if you don't mind ... are you willing to share your code for a while ... cause our intention is same i suppose ... to have a clock within form.... thanks in advance

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.