Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Creating an On screen Digital clock in

Author: DevASP
Download Source Code :

This article is about how you can create a on screen digital clock. On screen means the clock will stay on all windows and in the center of the computer screen

Steps you will do.



Start visual studio and create a new window application.


Set the following properties of the form.


Name = Form1

BackColor = White

Font = Microsoft Sans Serif, 8.25pt

FormBorderStyle = None

StartPosition = CenterScreen

TransparencyKey = 255, 192, 192

Opacity = 50%


Place a panel control on the form and set its following properties.


Name = panel1

Anchor = None

Backcolor = 255, 192, 192

Font = Microsoft Sans Serif, 8.25pt



Now place a text box control on the form and set its following properties.


Name = TextBox1

BackColor = 255, 192, 192

Font = Microsoft Sans Serif, 15.75pt, style=Bold

Text = “”

TextAlign = Center



Now add a new module in your project and add the following code in it and import the following namespace.


Imports System.Windows.Forms


Public Const WM_NCHITTEST = &H84

    Public Enum HitTestResult

        HTBORDER = 18

        HTBOTTOM = 15

        HTBOTTOMLEFT = 16

        HTBOTTOMRIGHT = 17

        HTCAPTION = 2

        HTCLIENT = 1

        HTERROR = (-2)

        HTGROWBOX = 4

        HTHSCROLL = 6

        HTLEFT = 10

        HTMAXBUTTON = 9

        HTMENU = 5

        HTMINBUTTON = 8

        HTNOWHERE = 0

        HTRIGHT = 11

        HTSYSMENU = 3

        HTTOP = 12

        HTTOPLEFT = 13

        HTTOPRIGHT = 14

        HTVSCROLL = 7

        HTTRANSPARENT = (-1)

        HTOBJECT = 19

        HTCLOSE = 20

        HTHELP = 21

    End Enum


    Public Sub FakeCaptionForCaptionlessWindow(ByVal fParent As Form,

ByRef m As Message, ByVal CaptionRectangle As Rectangle)


        If m.Msg = WM_NCHITTEST Then

            Dim ptClickLocation As New Point(m.LParam.ToInt32)

            ptClickLocation = fParent.PointToClient(ptClickLocation)

            If CaptionRectangle.Contains(ptClickLocation) Then

                m.Result = New IntPtr(HitTestResult.HTCAPTION)


                m.Result = New IntPtr(HitTestResult.HTCLIENT)

            End If

        End If

    End Sub



Now place a timer control on your form and set its following properties.


Name = Timer1

Enabled = True

Interval = 10



Now open the code window of the form and write the following code in it.


Dim rcCaption As Rectangle




Write the following code in the Tick event of timer object


Me.TextBox1.Text = Now.ToLongTimeString



Write the following code in the paint event of the form.


e.Graphics.FillRectangle(New SolidBrush(Color.Blue), rcCaption)




Now write the following code.


Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

        If m.Msg = WM_NCHITTEST Then

            Call FakeCaptionForCaptionlessWindow(Me, m, rcCaption)



        End If

    End Sub



Run your application and see the digital clock on your screen.



Article Comments
vey good

Posted on 8/24/2006 3:24:01 AM by saji

very very nice

Posted on 10/19/2006 6:46:38 AM by sujata

This is very useful i am from nigiria and i think that this program is very usefull to me and i am trying my best to keep up my good work

Posted on 9/28/2007 8:26:47 AM by chicalala

very fine

Posted on 2/20/2008 5:58:58 AM by Ravi

send example to me

Posted on 4/16/2008 1:48:26 AM by abualya

good hai yaar

Posted on 4/26/2008 11:34:37 AM by bhuvan

fantastic.....PLZ send example to me

Posted on 12/10/2009 11:48:23 PM by Thakur ShivPratap Singh

It's Very good article for .net developer

Jayant das

Posted on 5/30/2010 11:20:04 PM by jayant das

very..............G@@D Yaar ...................

Posted on 5/31/2010 5:10:39 AM by sunny bhardwaj

This is a very good idea of yours. It encourage the users just like me to free their minds towards the use of

Posted on 6/11/2010 4:29:18 AM by EGBA JOSHUA


Posted on 6/11/2010 4:39:33 AM by EGBA JOSHUA

Very Very Good!
Can you send me the explanation of the code, and how it works?

Thank you for sharing.

Posted on 7/1/2010 4:59:03 AM by Germz

Nice Article

Posted on 7/23/2010 7:53:53 AM by sriram

That is very good example and It is also very useful.

Posted on 8/3/2010 11:15:13 PM by Kelly Kostar

That is very good example and It is also very useful.

Posted on 8/3/2010 11:15:41 PM by Kelly Kostar

its a very helpful example...
it cud hav been much better if the output to ths eg must hav been shown here...

i want to display a clock in my project as, 00:00:00
and it shud take values of timing from a textbox aftr button is pressed n should start the clock as 00:00:01 and onwards...
can neone help me out
its urgent..
my email id is -

Posted on 9/27/2010 3:04:11 AM by abrar

hmmmm, nice...


Posted on 11/8/2010 9:50:09 AM by aLzNuttz

Add Article Comment:
Name :
Email Address :
Comments :
<< Creating a Temperature converter using

Disclaimer - Privacy
© 2002-2017