A fast and performing gauge, now in a dll for vb users






2.44/5 (9 votes)
Mar 11, 2007
2 min read

95932

3450
A short procedure for adding a nice gauge to your VS toolbox
Introduction
For those of us looking to use the great gauge class that A.J. Bauer wrote, in a VB.net project. After spending a few hours bopping around the internet in search of a decent looking yet free gauge control, I finally landed on the code project article "A fast and performing gauge", but to my horror it was written in C# (me = VB guy) and it did not use a DLL for the gauge class. Now, I am still fairly new to .net developement, but I was determined to use the gauge class in my VB.Net app, and I didnt want to recode it all in a VB class. So, this is what I did.
1. Opened a VS2005 project and chose Visual C#/windows/Class Library
2. Cut the contents of the original projects agauge.cs into my new class code, overwriting everything that was autogenerated.
3. In the solution explorer window, I added the references to System.Drawing and System.Windows.Forms
4. Debugging some broken definitions led me to copy the following lines from Agauge.Designer.cs...
private Sytem.ComponentModel.Icontainer components = null;
and...
private void InitializeComponent() { components = new System.ComponentModel.Container(); }
...into the new class.cs code, just before the public Agauge()
constructor...
//KO-Added for Conversion to DLL private System.ComponentModel.IContainer components = null; //KO-Added for Conversion to DLL private void InitializeComponent() { components = new System.ComponentModel.Container(); } public AGauge() { InitializeComponent(); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); }
5. A final edit to make the namespace match my project namespace AGauge
, and I was ready to build the DLL.
6. From my original VB project, I opened the toolbox, right-clicked on it, selected "Chose Items..." and then browsed to my newly created DLL, click open, and voila! A new toolbox control appeared allowing me to drag the gauge onto my VB form.
7. I spent the next few hours gleefully tweaking the myriad properties to make a couple of custom gauges that I needed for my project.
I do not presume to think that this is best or only way to accomplish what I was trying to do, but it did work, and I think that is something worth sharing...
P.S. After using the control for awhile, it became painfully evident that there was a problem with the ScaleLinesMajorStepValue property, so I re-opened the DLL project and searched for the symbol. I am not sure why but the original code was restricting the value to a number between the current MinValue and MaxValue properties. On the surface, this may seem to make sense, but in practice, it was giving me a pain in the neck while trying to tweak the properties. In the modified code above, I simply changed it to be whatever value is entered into the property window. The original line of code accompanies my comment above the edit.
Lastly, I would like to thank A.J. Bauer for sharing his awesome gauge class.