Skip to main content

Posts

Showing posts from August, 2008

ActiveX Stopwatch Timer Control

Here's an example of a StopWatch control implemented in Csharp and used as a control on a web client. The control needs to be register on the clients machine then added to the clients web application (in html) and then called from Javascript. <OBJECT id="activeXTimerControl" name="activeXTimerControl"  classid="clsid:4F3B57CE-D9CA-41c3-ACBD-EBB2380990E7"  style="width: 504px; height: 182px"  codebase="Bin/ActiveXTimerControl.dll" class="ActiveXTimerControl.TimerControl"> </OBJECT> To start the Stopwatch call Start() and to end call End() then call Time() to return the result as a string or use the AddTimeToGrid to add the time to a DataGrid Control (supplied by the StopWatch control) or call AddTimeToLabel which adds the time to a textbox. activeXTimerControl.Start(); ///do someting activeXTimerControl.Stop(); var time = activeXTimerControl....

AcitveX Controls - how to create one and call with Javascript

One way to get a .NET object to run in a browser is to create a User Control in .NET. You can then call this User Control from Javascript in your client. There's nothing magical about this except, it only works on IE and there are a few small bits that you must implement in order for your User Control to be picked up, the errors you get aren't very helpful so I recommend following these steps (Some of these I'm not sure if they're required but they've worked for me). Create a Class Project in Visual Studio 2005. Add a User Control to the project. In the User Control Designer add a TextBox Control Add a Property to your class to set the Text of the TextBox you've just added. public void AddText(string time) { if (_timerTextBox == null) { _timerTextBox = new System.Windows.Forms.TextBox(); _timerTextBox.Text = " Time (msec)"; } _timerTextBox.Text += ("\r\n" ...

Localization and Globalization

Using Localization from Code ASP.NET provides all the Localization you need by just adding .RESX files to your Web App in the right location but sometimes you want to invoke the Localization yourself. To do this you'll use the System.Resources.ResourceManager class. This allows you to get resources by simply supplying the name of the resource and the Culture but to setup the resource itself is a bit trickier (in Visual Studio 2005) as some of the files required have been removed from Visual Studio's Templates. Because of this you'll need to use some tools to create the Resource (and optionally the Assembly to store it know as Resource Assemblies or Satellite Assemblies). There are 3 steps to creating resources for use with ResourceManager: 1. Write a text file or .RESX file to hold your resources. 2. Compile the resources in step 1 into a .RESOURCES file. 3. Compile the .RESOURCES file in step 2 into a Satellite Assembly. 4. Locate the Satellite Assembly from step 3 ...