Click here to Skip to main content
15,867,308 members
Articles / Programming Languages / C#
Article

A Floating Popup Control

Rate me:
Please Sign up or sign in to vote.
3.64/5 (11 votes)
4 May 2006CPOL2 min read 115.5K   2.9K   68   16
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...

C#
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...

C#
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)


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 11:47
davicef8-Jul-08 11:47 
AnswerRe: calculatorbox component for .net compact framework ? Pin
H. S. Masud8-Jul-08 19:15
H. S. Masud8-Jul-08 19:15 
QuestionOccur Dialog "A project with an Output Type of Class Library cannot be started directly" Pin
lnakarin1-Feb-07 18:02
lnakarin1-Feb-07 18:02 
AnswerRe: Occur Dialog "A project with an Output Type of Class Library cannot be started directly" Pin
H. S. Masud2-Feb-07 21:25
H. S. Masud2-Feb-07 21:25 
GeneralRe: Occur Dialog "A project with an Output Type of Class Library cannot be started directly" Pin
lnakarin5-Feb-07 15:28
lnakarin5-Feb-07 15:28 
NewsMainform loses focuc - Solution Pin
Julian Ott14-Oct-06 11:42
Julian Ott14-Oct-06 11:42 
GeneralNice one Pin
fwsland23-Jul-06 5:45
fwsland23-Jul-06 5:45 
GeneralRe: Nice one Pin
H. S. Masud23-Jul-06 22:40
H. S. Masud23-Jul-06 22:40 
GeneralThe main form loses focus Pin
Yevgeni Zolotko5-May-06 22:07
Yevgeni Zolotko5-May-06 22:07 
NewsRe: The main form loses focus Pin
H. S. Masud5-May-06 22:15
H. S. Masud5-May-06 22:15 
GeneralRe: The main form loses focus Pin
Paul Bludov9-May-06 14:48
Paul Bludov9-May-06 14:48 
You can use ToolStripDropDown control. Here is a sample:

protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);

ToolStripDropDown tsdd = new ToolStripDropDown();
tsdd.Items.Add(new ToolStripControlHost(new ListView()));
tsdd.Show(PointToScreen(e.Location));
}

Just copy'n'paste it to a form and click on it's surface. Smile | :)
JokeRe: The main form loses focus Pin
H. S. Masud9-May-06 19:39
H. S. Masud9-May-06 19:39 
GeneralRe: The main form loses focus Pin
kleinecools21-Jun-06 21:29
kleinecools21-Jun-06 21:29 
GeneralRe: The main form loses focus Pin
Vedran Mikulcic9-Jun-11 3:58
Vedran Mikulcic9-Jun-11 3:58 
GeneralExcellent Calculator Control !!! Pin
Marcos Meli4-May-06 6:11
Marcos Meli4-May-06 6:11 
JokeRe: Excellent Calculator Control !!! Pin
H. S. Masud5-May-06 19:15
H. S. Masud5-May-06 19: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.