I have written an article in CodeProject titled as "A Calculator Control Box". It was useful to many developers like me. Some did not use the calculator control directly in their project. They modified the control to display it as a different control in a popup form. By this time, I needed the same thing too. So, I modified the control to display in any form as a popup window.
To display your own form in the floating popup control, you need to implement an interface named
IFloatingPopup. The interface is something like...
public interface IFloatingPopup
event CancelEventHandler PopupHiding;
event CancelEventHandler PopupShowing;
event EventHandler PopupHidden;
event EventHandler PopupShown;
In the implementation,
Hide have already been implemented in your form. You can inherit
frmFloatingBase where the interface has been implemented. So, you don't need to think about its implementation.
To use your own form, the following steps will help you...
frmFloatingDerived myderivedForm=new frmFloatingDerived();
The floating popup control has all the features of the calculator control, like auto-positioning the popup window. It displays the floating window at the best possible position in accordance to the control position at the screen.
Calculator Box Control
CalculatorBox is a user control, which provides specific features to provide numeric input, especially for financial information. This control can be used as a text box control. It is more like a combo box control. It has two modes. One is the normal mode where the user can provide input for a decimal number. Whenever the user wants to do some mathematical operations, the user can click on the arrow at the left, like in a combo box. It will display a calculator at the best possible place. The user can click on the calculator buttons, or use the keyboard to do the calculator. In text mode, if the user clicks any operation key (Add, Subtract, Multiply, or Divide), then it will automatically switch to the calculator mode with the button pressed. If the calculator loses its focus, then automatically, it will switch to text mode and the calculator will disappear.
If the user made some mistake in the calculation and wants to go back to the previous value, then user can press the Esc button. It will re-set to the previous value.
This control has two properties. The
Text property will provide whatever is available in the text box, and the
Value property will provide the decimal value.
I use the current culture information from the
CultureInfo class to decide the character for the decimal point. The decimal point is used for display as well as to accept input from the user. For example, the Spanish language uses coma as a decimal separator. So, if the user sets the current culture as Spanish, then the calculator control will automatically use the coma as the decimal separator.