June 10th, 2012 10:30 PM
#1
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
};
}
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
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks