Click here to Skip to main content
15,499,430 members
Articles / Programming Languages / C#
Posted 4 May 2006


68 bookmarked

A Floating Popup Control

Rate me:
Please Sign up or sign in to vote.
3.64/5 (11 votes)
4 May 2006CPOL2 min read
A floating popup control which can display any form.

Sample Image - FloatingPopup.jpg


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

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();

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


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

Written By
Software Developer (Senior) KAZ Software Limited
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

Questioncalculatorbox component for .net compact framework ? Pin
davicef8-Jul-08 12:47
Memberdavicef8-Jul-08 12:47 
AnswerRe: calculatorbox component for .net compact framework ? Pin
H. S. Masud8-Jul-08 20:15
MemberH. S. Masud8-Jul-08 20:15 
QuestionOccur Dialog "A project with an Output Type of Class Library cannot be started directly" Pin
lnakarin1-Feb-07 19:02
Memberlnakarin1-Feb-07 19:02 
AnswerRe: Occur Dialog "A project with an Output Type of Class Library cannot be started directly" Pin
H. S. Masud2-Feb-07 22:25
MemberH. S. Masud2-Feb-07 22:25 
GeneralRe: Occur Dialog "A project with an Output Type of Class Library cannot be started directly" Pin
lnakarin5-Feb-07 16:28
Memberlnakarin5-Feb-07 16:28 
NewsMainform loses focuc - Solution Pin
Julian Ott14-Oct-06 12:42
MemberJulian Ott14-Oct-06 12:42 
GeneralNice one Pin
fwsland23-Jul-06 6:45
Memberfwsland23-Jul-06 6:45 
GeneralRe: Nice one Pin
H. S. Masud23-Jul-06 23:40
MemberH. S. Masud23-Jul-06 23:40 
GeneralThe main form loses focus Pin
Yevgeni Zolotko5-May-06 23:07
MemberYevgeni Zolotko5-May-06 23:07 
NewsRe: The main form loses focus Pin
H. S. Masud5-May-06 23:15
MemberH. S. Masud5-May-06 23:15 
I agree with you. Thanks for your comment.

Hasan Shahriar Masud
Senior Software Engineer
Kaz Software limited
Dhaka, Bangladesh
GeneralRe: The main form loses focus Pin
Paul Bludov9-May-06 15:48
MemberPaul Bludov9-May-06 15:48 
JokeRe: The main form loses focus Pin
H. S. Masud9-May-06 20:39
MemberH. S. Masud9-May-06 20:39 
GeneralRe: The main form loses focus Pin
kleinecools21-Jun-06 22:29
Memberkleinecools21-Jun-06 22:29 
GeneralRe: The main form loses focus Pin
Vedran Mikulcic9-Jun-11 4:58
MemberVedran Mikulcic9-Jun-11 4:58 
GeneralExcellent Calculator Control !!! Pin
Marcos Meli4-May-06 7:11
MemberMarcos Meli4-May-06 7:11 
JokeRe: Excellent Calculator Control !!! Pin
H. S. Masud5-May-06 20:15
MemberH. S. Masud5-May-06 20:15 

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

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