Having trouble using setText() for RichTextField and other GUI issues.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Having trouble using setText() for RichTextField and other GUI issues.

  1. #1

    Question Having trouble using setText() for RichTextField and other GUI issues.

    I'm having trouble with two things of immediate concern

    1.) I cannot figure out how to read in text from a file, at least to able to read in line breaks like

    "bla bla bla bal

    bla bla bla bla"

    and also to be able to set the text. It's complaining that I cannot convert from std::String to System::String. What does the L label stand for?

    2.) I don't know how to reference and load other forms in a form. For instance if I have window1 and I want it to have a button that will open window/form 2, how do I do that? I think the click action or whatever is the equivalent of a java ActionListener. Anyway, I've tried that without success. Right now, I'm working on the readin.

    Code:
    #pragma once
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    namespace ReadinTextAreaExample {
    
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	
    	/// <summary>
    	/// Summary for Form1
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Panel^  panel1;
    	protected: 
    	private: System::Windows::Forms::RichTextBox^  richTextBox1;
    	private: System::Windows::Forms::BindingNavigator^  bindingNavigator1;
    	private: System::Windows::Forms::ToolStripButton^  bindingNavigatorAddNewItem;
    	private: System::Windows::Forms::ToolStripLabel^  bindingNavigatorCountItem;
    	private: System::Windows::Forms::ToolStripButton^  bindingNavigatorDeleteItem;
    	private: System::Windows::Forms::ToolStripButton^  bindingNavigatorMoveFirstItem;
    	private: System::Windows::Forms::ToolStripButton^  bindingNavigatorMovePreviousItem;
    	private: System::Windows::Forms::ToolStripSeparator^  bindingNavigatorSeparator;
    	private: System::Windows::Forms::ToolStripTextBox^  bindingNavigatorPositionItem;
    	private: System::Windows::Forms::ToolStripSeparator^  bindingNavigatorSeparator1;
    	private: System::Windows::Forms::ToolStripButton^  bindingNavigatorMoveNextItem;
    	private: System::Windows::Forms::ToolStripButton^  bindingNavigatorMoveLastItem;
    	private: System::Windows::Forms::ToolStripSeparator^  bindingNavigatorSeparator2;
    	private: System::ComponentModel::IContainer^  components;
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    
    		
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->components = (gcnew System::ComponentModel::Container());
    			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
    
    			ifstream fin;
    			fin.open("s1.txt", ifstream::in);
    
    			string text = "";
    			
    			string temp = "";
    
    			fin >> temp;
    
    			text = text + temp;
    
    
    
    
    			this->panel1 = (gcnew System::Windows::Forms::Panel());
    			this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
    			this->bindingNavigator1 = (gcnew System::Windows::Forms::BindingNavigator(this->components));
    			this->bindingNavigatorMoveFirstItem = (gcnew System::Windows::Forms::ToolStripButton());
    			this->bindingNavigatorMovePreviousItem = (gcnew System::Windows::Forms::ToolStripButton());
    			this->bindingNavigatorSeparator = (gcnew System::Windows::Forms::ToolStripSeparator());
    			this->bindingNavigatorPositionItem = (gcnew System::Windows::Forms::ToolStripTextBox());
    			this->bindingNavigatorCountItem = (gcnew System::Windows::Forms::ToolStripLabel());
    			this->bindingNavigatorSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
    			this->bindingNavigatorMoveNextItem = (gcnew System::Windows::Forms::ToolStripButton());
    			this->bindingNavigatorMoveLastItem = (gcnew System::Windows::Forms::ToolStripButton());
    			this->bindingNavigatorSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
    			this->bindingNavigatorAddNewItem = (gcnew System::Windows::Forms::ToolStripButton());
    			this->bindingNavigatorDeleteItem = (gcnew System::Windows::Forms::ToolStripButton());
    			this->panel1->SuspendLayout();
    			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->bindingNavigator1))->BeginInit();
    			this->bindingNavigator1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// panel1
    			// 
    			this->panel1->Controls->Add(this->bindingNavigator1);
    			this->panel1->Controls->Add(this->richTextBox1);
    			this->panel1->Location = System::Drawing::Point(1, 0);
    			this->panel1->Name = L"panel1";
    			this->panel1->Size = System::Drawing::Size(803, 417);
    			this->panel1->TabIndex = 0;
    			// 
    			// richTextBox1
    			// 
    			this->richTextBox1->Location = System::Drawing::Point(11, 28);
    			this->richTextBox1->Name = L"richTextBox1";
    			this->richTextBox1->Size = System::Drawing::Size(777, 386);
    			this->richTextBox1->TabIndex = 0;
    			this->richTextBox1->Text =text;
    			// 
    			// bindingNavigator1
    			// 
    			this->bindingNavigator1->AddNewItem = this->bindingNavigatorAddNewItem;
    			this->bindingNavigator1->CountItem = this->bindingNavigatorCountItem;
    			this->bindingNavigator1->DeleteItem = this->bindingNavigatorDeleteItem;
    			this->bindingNavigator1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(11) {this->bindingNavigatorMoveFirstItem, 
    				this->bindingNavigatorMovePreviousItem, this->bindingNavigatorSeparator, this->bindingNavigatorPositionItem, this->bindingNavigatorCountItem, 
    				this->bindingNavigatorSeparator1, this->bindingNavigatorMoveNextItem, this->bindingNavigatorMoveLastItem, this->bindingNavigatorSeparator2, 
    				this->bindingNavigatorAddNewItem, this->bindingNavigatorDeleteItem});
    			this->bindingNavigator1->Location = System::Drawing::Point(0, 0);
    			this->bindingNavigator1->MoveFirstItem = this->bindingNavigatorMoveFirstItem;
    			this->bindingNavigator1->MoveLastItem = this->bindingNavigatorMoveLastItem;
    			this->bindingNavigator1->MoveNextItem = this->bindingNavigatorMoveNextItem;
    			this->bindingNavigator1->MovePreviousItem = this->bindingNavigatorMovePreviousItem;
    			this->bindingNavigator1->Name = L"bindingNavigator1";
    			this->bindingNavigator1->PositionItem = this->bindingNavigatorPositionItem;
    			this->bindingNavigator1->Size = System::Drawing::Size(803, 25);
    			this->bindingNavigator1->TabIndex = 1;
    			this->bindingNavigator1->Text = L"bindingNavigator1";
    			// 
    			// bindingNavigatorMoveFirstItem
    			// 
    			this->bindingNavigatorMoveFirstItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
    			this->bindingNavigatorMoveFirstItem->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"bindingNavigatorMoveFirstItem.Image")));
    			this->bindingNavigatorMoveFirstItem->Name = L"bindingNavigatorMoveFirstItem";
    			this->bindingNavigatorMoveFirstItem->RightToLeftAutoMirrorImage = true;
    			this->bindingNavigatorMoveFirstItem->Size = System::Drawing::Size(23, 22);
    			this->bindingNavigatorMoveFirstItem->Text = L"Move first";
    			// 
    			// bindingNavigatorMovePreviousItem
    			// 
    			this->bindingNavigatorMovePreviousItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
    			this->bindingNavigatorMovePreviousItem->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"bindingNavigatorMovePreviousItem.Image")));
    			this->bindingNavigatorMovePreviousItem->Name = L"bindingNavigatorMovePreviousItem";
    			this->bindingNavigatorMovePreviousItem->RightToLeftAutoMirrorImage = true;
    			this->bindingNavigatorMovePreviousItem->Size = System::Drawing::Size(23, 22);
    			this->bindingNavigatorMovePreviousItem->Text = L"Move previous";
    			// 
    			// bindingNavigatorSeparator
    			// 
    			this->bindingNavigatorSeparator->Name = L"bindingNavigatorSeparator";
    			this->bindingNavigatorSeparator->Size = System::Drawing::Size(6, 25);
    			// 
    			// bindingNavigatorPositionItem
    			// 
    			this->bindingNavigatorPositionItem->AccessibleName = L"Position";
    			this->bindingNavigatorPositionItem->AutoSize = false;
    			this->bindingNavigatorPositionItem->Name = L"bindingNavigatorPositionItem";
    			this->bindingNavigatorPositionItem->Size = System::Drawing::Size(50, 23);
    			this->bindingNavigatorPositionItem->Text = L"0";
    			this->bindingNavigatorPositionItem->ToolTipText = L"Current position";
    			// 
    			// bindingNavigatorCountItem
    			// 
    			this->bindingNavigatorCountItem->Name = L"bindingNavigatorCountItem";
    			this->bindingNavigatorCountItem->Size = System::Drawing::Size(35, 22);
    			this->bindingNavigatorCountItem->Text = L"of {0}";
    			this->bindingNavigatorCountItem->ToolTipText = L"Total number of items";
    			// 
    			// bindingNavigatorSeparator1
    			// 
    			this->bindingNavigatorSeparator1->Name = L"bindingNavigatorSeparator";
    			this->bindingNavigatorSeparator1->Size = System::Drawing::Size(6, 25);
    			// 
    			// bindingNavigatorMoveNextItem
    			// 
    			this->bindingNavigatorMoveNextItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
    			this->bindingNavigatorMoveNextItem->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"bindingNavigatorMoveNextItem.Image")));
    			this->bindingNavigatorMoveNextItem->Name = L"bindingNavigatorMoveNextItem";
    			this->bindingNavigatorMoveNextItem->RightToLeftAutoMirrorImage = true;
    			this->bindingNavigatorMoveNextItem->Size = System::Drawing::Size(23, 22);
    			this->bindingNavigatorMoveNextItem->Text = L"Move next";
    			// 
    			// bindingNavigatorMoveLastItem
    			// 
    			this->bindingNavigatorMoveLastItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
    			this->bindingNavigatorMoveLastItem->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"bindingNavigatorMoveLastItem.Image")));
    			this->bindingNavigatorMoveLastItem->Name = L"bindingNavigatorMoveLastItem";
    			this->bindingNavigatorMoveLastItem->RightToLeftAutoMirrorImage = true;
    			this->bindingNavigatorMoveLastItem->Size = System::Drawing::Size(23, 22);
    			this->bindingNavigatorMoveLastItem->Text = L"Move last";
    			// 
    			// bindingNavigatorSeparator2
    			// 
    			this->bindingNavigatorSeparator2->Name = L"bindingNavigatorSeparator";
    			this->bindingNavigatorSeparator2->Size = System::Drawing::Size(6, 25);
    			// 
    			// bindingNavigatorAddNewItem
    			// 
    			this->bindingNavigatorAddNewItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
    			this->bindingNavigatorAddNewItem->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"bindingNavigatorAddNewItem.Image")));
    			this->bindingNavigatorAddNewItem->Name = L"bindingNavigatorAddNewItem";
    			this->bindingNavigatorAddNewItem->RightToLeftAutoMirrorImage = true;
    			this->bindingNavigatorAddNewItem->Size = System::Drawing::Size(23, 22);
    			this->bindingNavigatorAddNewItem->Text = L"Add new";
    			// 
    			// bindingNavigatorDeleteItem
    			// 
    			this->bindingNavigatorDeleteItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
    			this->bindingNavigatorDeleteItem->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"bindingNavigatorDeleteItem.Image")));
    			this->bindingNavigatorDeleteItem->Name = L"bindingNavigatorDeleteItem";
    			this->bindingNavigatorDeleteItem->RightToLeftAutoMirrorImage = true;
    			this->bindingNavigatorDeleteItem->Size = System::Drawing::Size(23, 22);
    			this->bindingNavigatorDeleteItem->Text = L"Delete";
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(801, 413);
    			this->Controls->Add(this->panel1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->panel1->ResumeLayout(false);
    			this->panel1->PerformLayout();
    			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->bindingNavigator1))->EndInit();
    			this->bindingNavigator1->ResumeLayout(false);
    			this->bindingNavigator1->PerformLayout();
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	};
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    Your code has nothing to do with the Visual C++, nor is it a native C++ one. So your question does not belong to this Forum
    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.
    It seems to be related to managed C++, so try to ask in the managed C++/CLI forum.
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,062

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    [ moved thread ]

  4. #4
    Join Date
    Jul 2002
    Posts
    2,512

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    1. http://msdn.microsoft.com/en-us/library/3f99sst7.aspx
    L means Unicode string.

    2. Subscribe to button click event and open another form from this event handler.

    Why do you need C++/CLI for this? Use C# !

  5. #5

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    What about the text thing? How do I handle that? I need to know how to handle it if the text is being set from text being read in from a file.

    What is C#? I never coded in C#. The best I can make of C# is that it's an enhanced version of C++, or so I think I've heard.

    I don't know any code in C#. I've learned some of how the C++ GUI elements work by looking at the code from elements it generated with the visual part and have used to make my own elements that were auto-generated.

    Also, what does this symbol mean when it comes after a class, I know a pointer is * but what is ^ ?

  6. #6
    Join Date
    Jul 2002
    Posts
    2,512

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    Quote Originally Posted by jedipenguin View Post
    I need to know how to handle it if the text is being set from text being read in from a file.
    This question looks somewhat cryptic...

    The link in my first answer shows how to load text file to RichTextBox - this was your question.

    If you want to work with .NET, use C#. This language is good for any programmer with previous C/C++/Java experience, it is default choice for .NET programming.
    C++/CLI is used for managed-unmanaged interoperability. If you don't know what is this, or if you don't need this feature, this means, you don't need C++/CLI.
    goToC#

  7. #7

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    I'm using forms as I don't know how to work the visual C++ part for the other things and also, I suppose I could use it for the Win 32 API, but the problem is that I could only add what they have and not be able to write any of my own. (Also, I don't think I got it to work that well on Win 32 for Visual anyway. What is .NET?

    As for the C++ GUI stuff, which should be similar in C#, whatever that is, if it really is based off of C++, anyway, in part I wanted to learn GUI programming, in part because I'm taking a graphics course and it's in C++ and unfortunately, as I said, though I now get the basics a little bit better now, pointers and references are the things that confuse me the most, and when and when not to use the keyword "new" or now, some new thing called "gcnew".

    I normally don't use the keyword "new" now as it invovles annoying deletion later (or annoying memory leaks if I forget to delete!!!).

    Anyway, I checked at http://www.cplusplus.com/search.do?q=System&#37;3A%3AString

    and they don't have the C++ GUI API.

    I'm using RichTextBox because that kind of thing, going with forms, was the only one that I can manage to get the visual builder to work on, or at least somewhat figure out how to work it. I don't know what .NET is and how this fits into all of this. I thought that .NET was internet or something as in something called ASP.NET

    I'm suspecting to some degree that, kind of like Java ME, there is no "standard" API for C++ GUIs. Am I correct in that assumption?

  8. #8
    Join Date
    Jul 2002
    Posts
    2,512

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    So, you are working with C++ and looking for GUI toolkit to make user interface?
    You can use Windows API, MFC, WTL (Windows-specific), or cross-platform Qt, wxWidgets. Using .NET Windows Forms GUI is not the best choice, especially if you don't know what is .NET and don't need it at all...

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Having trouble using setText() for RichTextField and other GUI issues.

    Quote Originally Posted by jedipenguin View Post
    What is C#? I never coded in C#. The best I can make of C# is that it's an enhanced version of C++, or so I think I've heard.
    Quote Originally Posted by jedipenguin View Post
    Anyway, I checked at http://www.cplusplus.com/search.do?q=System%3A%3AString

    [...] I don't know what .NET is and how this fits into all of this. I thought that .NET was internet or something as in something called ASP.NET

    I'm suspecting to some degree that, kind of like Java ME, there is no "standard" API for C++ GUIs. Am I correct in that assumption?
    System::String is a .NET framework type (called System.String in at least most of the other .NET languages) and has nothing to do with the native C++ documented and discussed on cplusplus.com. And it should be noted that, despite the similar name and for large parts identical syntax, C++ and C++/CLI are distinct programming languages.

    And yes, the definition of the language C++ and its standard library doesn't even remotely touch any GUI thematics. Instead this is the responsibility of a bunch of additional GUI frameworks/libraries, some of which have been mentioned by Alex F, built upon the C++ standard, but otherwise independent from it..

    Perhaps some of these are helpful:

    http://en.wikipedia.org/wiki/C_Sharp...mming_language)
    http://en.wikipedia.org/wiki/.NET_Framework
    http://en.wikipedia.org/wiki/C%2B%2B/CLI
    http://forums.codeguru.com/showthread.php?t=521190
    http://forums.codeguru.com/showthread.php?t=519948
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center