Introduction

I've been developing applications for Engineering and CAD/GIS for quite some time. Most of the applications were designed to get inputs from the user for engineering/CAD/GIS calculations. In this process, it has been obsorved that most of the inputs that we recieve from the user is either hand calculated or calculated with the use of standard windows calculator before he/she inputs the value into our application. And there have been requests from the user to give them an in-place calculator so that it can improve their productivity and at the same time can reduce the manual errors. So the result of it is this Drop-Down Calculator control which I'm going to share with you.

Background (optional)

The idea is to provide a drop-down button, which can visualize an in-place calculator when the user hits it. Since we receive inputs from the user from different user controls like textbox, updown, combobox etc. The Drop-Down calculator should be flexible enough to be associated with these standard input controls. Since all the UI Forms controls are inherited from System.Windows.Forms.Control, We can utilize the Text Property provided by the Control to communicate our results from calculator.

Using the code

The Control Design

The Control contains a dialog with calculator like buttons and appropriate code to compute the results based on the user input. This dialog box is displayed when the drop-down button is clicked. The user control to which the results are to be re-directed is set through property named "AssociatedControl"

' The property that can be used at design-time
' to set the control associated with the calculator
PublicProperty AssociatedControl() As Control
GetReturnMe.ownerControl
EndGetSet(ByVal value As Control)
Me.ownerControl = value
EndSetEndProperty

The next task is to re-position the calculator dialog such that it appears like a Drop-Down from the button. This is achieved by a procedure named "RepositionCalc" in the calculator dialog.

Using the Control

You can add the Drop-Down calculator control to your toolbox by pointing to PopupCalculator.dll in "Choose Toolbox Items" dialog box. Once the Drop-down button is placed on the form, It can be associated with any control (not to self) which already exists in the form. Use the "Properties" window to set the "AssociatedControl" property of the Drop-down button. Now the Drop-Down calculator will take care of in-place calculator functionality

Share

About the Author

Working as a Techical Lead in a leading Geographical Information Systems development organisation based in Trichy (India).
Started learning .NET technologies through the various articles hosted in codeproject. And was looking for a day when I can post articles. I hope I did it
Visit my other sites
http://www.text2pdf.co.cc
http://www.pdfmaker.co.cc