Click here to Skip to main content
Click here to Skip to main content
Go to top

Multi-line InputBox control - MC++

, 7 Jun 2002
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 Sivakumar

United States United States
Nish is a real nice guy who has been writing code since 1990 when he first got his hands on an 8088 with 640 KB RAM. Originally from sunny Trivandrum in India, he has been living in various places over the past few years and often thinks it’s time he settled down somewhere.
 
Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - www.voidnish.com where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff - blog.voidnish.com.
 
Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket as well as a programming book – Extending MFC applications with the .NET Framework.
 
Nish's latest book C++/CLI in Action published by Manning Publications is now available for purchase. You can read more about the book on his blog.
 
Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.

Comments and Discussions

 
QuestionAnd where is the mfc-code? Pinmembergunag3-Aug-06 2:45 
GeneralCodeProject.WinForms Pinmembersglaserintermet14-Jul-04 4:06 
GeneralGreat work, Nish PinmemberTom Archer7-Jul-03 15:54 
GeneralRe: Great work, Nish PineditorNishant S7-Jul-03 16:06 
GeneralA InputBox exists in the framework PinmemberRama Krishna8-Jun-02 15:38 
GeneralRe: A InputBox exists in the framework PinmemberNish - Native CPian8-Jun-02 15:46 
GeneralRe: A InputBox exists in the framework PinmemberRama Krishna8-Jun-02 15:55 
GeneralRe: A InputBox exists in the framework PinmemberNish - Native CPian8-Jun-02 16:02 
GeneralRe: A InputBox exists in the framework PinmemberKannan Kalyanaraman9-Jun-02 21:47 
GeneralRe: A InputBox exists in the framework PinmemberNish - Native CPian10-Jun-02 0:45 
GeneralRe: A InputBox exists in the framework PineditorNishant S9-Feb-03 8:57 
GeneralRe: A InputBox exists in the framework PinmemberRama Krishna10-Feb-03 3:45 
GeneralRe: A InputBox exists in the framework PineditorNishant S10-Feb-03 18:21 
GeneralHeeeeyyyyy! PinsitebuilderMichael Dunn8-Jun-02 9:31 
GeneralRe: Heeeeyyyyy! PinmemberNish - 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 | Mobile
Web03 | 2.8.140926.1 | Last Updated 8 Jun 2002
Article Copyright 2002 by Nish Sivakumar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid