Click here to Skip to main content
11,581,186 members (58,020 online)
Click here to Skip to main content

Multi-line InputBox control - MC++

, 7 Jun 2002 CPOL 119.1K 1.7K 26
Rate this:
Please Sign up or sign in to vote.
A .NET port of my MFC CFrameWnd derived InputBox class, written using MC++

Screenshots

Normal single-line InputBox

Multi-line InputBox

Demo app

Using the class

Just add a reference to InputBox.dll in your project. The class is part of the namespace CodeProject.WinForms. So you might want to add using CodeProject.WinForms on top of your source files. Of course that is if you are using C#. For an MC++ app you need to put using namespace CodeProject.Winforms on top of your source files.

InputBox Constructor

InputBox(); - This creates a normal InputBox with a single Input Line
InputBox(bool); - Depending on the bool you pass, this overload will create a multi-line InputBox if you pass true and a single line InputBox if you pass false

Example:-

InputBox m_ib = new InputBox();
InputBox m_multi_ib = new InputBox(true);

Show() - The key function

This has two overloads.

String* Show(String* prompt);

String* Show(String* prompt, String* title);

prompt - This is the prompt text that will appear in the InputBox. It's a Label control and thus it will word wrap.

title - This is the window title of the InputBox

Return Value

The String that was entered is returned, if the OK button was clicked. If the Cancel button was clicked an empty string is returned.

Sample Code

InputBox m_ib = new InputBox(true);
this.textBox2.Text = m_ib.Show("Enter your address please.",
    "Your address");

The class structure

// InputBox.h

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Windows::Forms;


namespace CodeProject
{
    namespace WinForms
    {
        public __gc class InputBox
        {
        private:
            Form* InputForm;
            TextBox* InputText;
            Label* PromptText;
            Button* BtnOk;
            Button* BtnCancel;
            bool m_multiline;

            void InitializeComponent();
            String* Show();
            void BtnOk_Click(Object* sender,
                EventArgs* e);
            void BtnCancel_Click(Object* sender,
                EventArgs* e);
        public:
            InputBox();
            InputBox(bool);
            String* Show(String* prompt);
            String* Show(String* prompt, String* title);
            
        };
    }
}

License

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

Share

About the Author

Nish Nishant
United States United States
Nish Nishant is a Software Architect/Consultant based out of Columbus, Ohio. He has over 15 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish is a recipient of the annual Microsoft Visual C++ MVP Award since 2002 (13 consecutive awards as of 2014).

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored
C++/CLI in Action for Manning Publications in 2005, and had previously co-authored
Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on CodeProject.com and another 250+ blog articles on his
WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : You can reach Nish on his google email id voidnish.

Website and Blog

You may also be interested in...

Comments and Discussions

 
QuestionAnd where is the mfc-code? Pin
gunag3-Aug-06 2:45
membergunag3-Aug-06 2:45 
GeneralCodeProject.WinForms Pin
sglaserintermet14-Jul-04 4:06
membersglaserintermet14-Jul-04 4:06 
GeneralGreat work, Nish Pin
Tom Archer7-Jul-03 15:54
memberTom Archer7-Jul-03 15:54 
GeneralRe: Great work, Nish Pin
Nishant S7-Jul-03 16:06
editorNishant S7-Jul-03 16:06 
GeneralA InputBox exists in the framework Pin
Rama Krishna8-Jun-02 15:38
memberRama Krishna8-Jun-02 15:38 
GeneralRe: A InputBox exists in the framework Pin
Nish - Native CPian8-Jun-02 15:46
memberNish - Native CPian8-Jun-02 15:46 
GeneralRe: A InputBox exists in the framework Pin
Rama Krishna8-Jun-02 15:55
memberRama Krishna8-Jun-02 15:55 
GeneralRe: A InputBox exists in the framework Pin
Nish - Native CPian8-Jun-02 16:02
memberNish - Native CPian8-Jun-02 16:02 
GeneralRe: A InputBox exists in the framework Pin
Kannan Kalyanaraman9-Jun-02 21:47
memberKannan Kalyanaraman9-Jun-02 21:47 
GeneralRe: A InputBox exists in the framework Pin
Nish - Native CPian10-Jun-02 0:45
memberNish - Native CPian10-Jun-02 0:45 
Kannan Kalyanaraman wrote:
the interesting part is its still version 1.0

True. I wonder what they can add in Version 2 Smile | :)

Nish



Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Buy it, read it and admire me Smile | :)

GeneralRe: A InputBox exists in the framework Pin
Nishant S9-Feb-03 8:57
editorNishant S9-Feb-03 8:57 
GeneralRe: A InputBox exists in the framework Pin
Rama Krishna10-Feb-03 3:45
memberRama Krishna10-Feb-03 3:45 
GeneralRe: A InputBox exists in the framework Pin
Nishant S10-Feb-03 18:21
editorNishant S10-Feb-03 18:21 
GeneralHeeeeyyyyy! Pin
Michael Dunn8-Jun-02 9:31
sitebuilderMichael Dunn8-Jun-02 9:31 
GeneralRe: Heeeeyyyyy! Pin
Nish - Native CPian8-Jun-02 13:34
memberNish - Native CPian8-Jun-02 13:34 

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
Web04 | 2.8.150603.1 | Last Updated 8 Jun 2002
Article Copyright 2002 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid