Visual C++ .NET Controls: A Memo


 
Microsoft .Net doesn't have a control called memo. I use memo as a control we are used to using in Borland C++ Builder based on its rich list of controls.

A memo is text-based control that uses the same functionality as a text box except that it can display its text on multiple lines, can accept the Tab key, can allow the user to move to the next line when pressing Enter, can wrap text, and can display scroll bars.

To create a memo in MS .Net application, use the TextBox class.

  1. Start Microsoft Visual Studio .NET
  2. On the Start Page, click New Project (alternatively, on the main menu, you can click File -> New -> Project...)
  3. On the New Project dialog box, in the Project Types tree list, click Visual C++ Projects
  4. In the Templates list, click Managed C++ Empty Project
  5. In the Name edit box, replace the <Enter name> content with Memo Example
  6. In the Location combo box, accept the suggestion or type your own. If you don't have any, type C:\Programs\MSVC.NET
  7. Click OK
  8. On the main menu, click Project -> Add New Item...
  9. In the Add New Item dialog box, in the Templates list, click C++ File
  10. In the Name box, replace <Enter name> with Main and click OK
  11. Replace the contents of the empty file with the following:
     
    #using <mscorlib.dll>
    #using <System.dll>
    #using <System.Drawing.dll>
    #using <System.Windows.Forms.dll>
    
    using namespace System;
    using namespace System::Drawing;
    using namespace System::Windows::Forms;
    
    __gc class SimpleForm : public Form
    {
    public:
    	SimpleForm();
    private:
    	// Declare a pointer to TextBox
    	TextBox *Editor;
    };
    
    SimpleForm::SimpleForm()
    {
    	this->Text = S"Editor";
    	this->Size = Point(600, 420);
    
    	// Initialize the declared TextBox variable
        	Editor = new TextBox();
        
        	// Allow the user to press Enter
    	// to move to the next line
        	Editor->AcceptsReturn = true;
        	// Allow the user to press TAB key to create indentation
    	// in the memo or for any other reason
        	Editor->AcceptsTab = true;
        	// Set the Multiline property to true
        	Editor->Multiline = true;
        	// Add a vertical scroll bar by default to the memo
    	Editor->ScrollBars = ScrollBars::Vertical;
        	// Allow the memo to wrap text
        	Editor->WordWrap = true;
    	// Let the memo occupy the whole client area
    	Editor->Dock = DockStyle::Fill;
        	// After creating the control, add it to the form
    	this->Controls->Add(Editor);
    }
    
    int __stdcall WinMain()
    {
    	SimpleForm * FM = new SimpleForm();
    	Application::Run(FM);
    
    	return 0;
    }
  12. Press Ctrl + F5 to test the application

Related Examples:

Body Tag Formatter

 

Home Copyright © 2002 FunctionX, Inc.