Take the 2-minute tour ×

I am making a quiz application where I would need to have a timer. I was wondering if I can use JavaScript timer on visual studio windows form? It would look nicer with a graphical timer rather then having a number count down.

If yes, then can someone give me a example code on how the JavaScript code is used within a c# windows form?

share|improve this question
You have also timer component in Visual Studio - why don't you use it? You want analog - draw it (dotnetaid.com/2011/08/04/…) on form or panel. –  mj82 Nov 11 '12 at 19:08
You can't just call server methods from the client (unless the framework specifially supports it), but the server can produce enough data for the client to do the rest. –  Jan Dvorak Nov 11 '12 at 19:09
add comment

2 Answers

up vote 2 down vote accepted

Windows Forms don't natively support javascript execution. You'd normally create a graphical timer in a Windows Forms application using Windows controls or GDI+ - or perhaps by embedding a WPF control.

However, you could embed a WebBrowser control in a Windows Forms application. The WebBrowser can display HTML and execute javascript. It's really just an embedded IE control.

Here are some examples of using GDI+ in a Windows Forms application to draw an analog clock:

share|improve this answer
add comment

While this post isn't necessarily asking how to use visual studio in a windows form in the right context, there is a way to do using a WebBrowser control. Most likely, you would already have a WebBrowser control and just want to communicate between the WebBrowser document and the host winform.

The secret is in that "Your scripting code can access your application through the window.external object, which is a built-in DOM object provided for host access, and which maps to an object that you specify for the ObjectForScripting property."


If you are looking for how to use javascript in a webform, you might just consider using a WebBrowser control and an hmtl document.

share|improve this answer
add comment

Your Answer


