5,696,038 members and growing! (13,253 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Windows Forms     Intermediate

Multi-line InputBox control - MC++

By Nishant Sivakumar

A .NET port of my MFC CFrameWnd derived InputBox class, written using MC++
C++/CLI, C#, VC7, C++Windows, .NET, .NET 1.0, Win2K, WinXPVS.NET2002, Visual Studio, Dev

Posted: 7 Jun 2002
Updated: 7 Jun 2002
Views: 83,992
Bookmarked: 13 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
38 votes for this Article.
Popularity: 5.76 Rating: 3.65 out of 5
1 vote, 3.8%
1
0 votes, 0.0%
2
1 vote, 3.8%
3
0 votes, 0.0%
4
24 votes, 92.3%
5

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nishant Sivakumar


Sitebuilder, Mvp
Nish is a real nice guy living in Atlanta, who has been coding since 1990, when he was 13 years old. Originally from sunny Trivandrum in India, he recently moved to Atlanta from Toronto and is a little sad that he won't be able to play in snow anymore.

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.
Location: United States United States

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 15 of 15 (Total in Forum: 15) (Refresh)FirstPrevNext
QuestionAnd where is the mfc-code?membergunag3:45 3 Aug '06  
GeneralCodeProject.WinFormsmembersglaserintermet5:06 14 Jul '04  
GeneralGreat work, NishmemberTom Archer16:54 7 Jul '03  
GeneralRe: Great work, NisheditorNishant S17:06 7 Jul '03  
GeneralA InputBox exists in the frameworkmemberRama Krishna16:38 8 Jun '02  
GeneralRe: A InputBox exists in the frameworkmemberNish - Native CPian16:46 8 Jun '02  
GeneralRe: A InputBox exists in the frameworkmemberRama Krishna16:55 8 Jun '02  
GeneralRe: A InputBox exists in the frameworkmemberNish - Native CPian17:02 8 Jun '02  
GeneralRe: A InputBox exists in the frameworkmemberKannan Kalyanaraman22:47 9 Jun '02  
GeneralRe: A InputBox exists in the frameworkmemberNish - Native CPian1:45 10 Jun '02  
GeneralRe: A InputBox exists in the frameworkeditorNishant S9:57 9 Feb '03  
GeneralRe: A InputBox exists in the frameworkmemberRama Krishna4:45 10 Feb '03  
GeneralRe: A InputBox exists in the frameworkeditorNishant S19:21 10 Feb '03  
GeneralHeeeeyyyyy!sitebuilderMichael Dunn10:31 8 Jun '02  
GeneralRe: Heeeeyyyyy!memberNish - Native CPian14:34 8 Jun '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 Jun 2002
Editor: Nishant Sivakumar
Copyright 2002 by Nishant Sivakumar
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project