Click here to Skip to main content
Click here to Skip to main content

A Floating Popup Control

, 4 May 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A floating popup control which can display any form.

Sample Image - FloatingPopup.jpg

Introduction

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.

Description

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;
    void Show();
    void Hide();
    void ForceShow();
    System.Windows.Forms.UserControl UserControl
    {
        get;
        set;
    }
    void SetAutoLocation();
    Form PopupForm
    {
        get;
    }
}

In the implementation, Show and 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();
myderivedForm.UserControl=floatingBox1;
floatingBox1.Popup=myderivedForm;

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

The 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.

Sample Image

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.

Culture Support

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.

Culture Support

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

H. S. Masud
Software Developer (Senior) KAZ Software Limited
Bangladesh Bangladesh
No Biography provided

Comments and Discussions

 
GeneralExcellent Calculator Control !!! PinmemberMarcos Meli4-May-06 7:11 
JokeRe: Excellent Calculator Control !!! PinmemberH. S. Masud5-May-06 20:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411022.1 | Last Updated 4 May 2006
Article Copyright 2006 by H. S. Masud
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid