オリジナルのまとめて管理できるメモ帳を作りたい
Posted: 2011年4月20日(水) 22:36
下記で質問したものです。
http://dixq.net/forum/viewtopic.php?f=3 ... xml#p66304
ご連絡が遅くなってしまい申し訳ありませんでした。
クラス化してみたのですが初期化がおかしい様でエラーが取ることができません。
\multieditor\Form1.h(41) : error C2143: 構文エラー : ')' が ';' の前にありません。
また保存の仕方もよくわからないのですが宜しければソースを今一度みては頂けないでしょうか。
http://dixq.net/forum/viewtopic.php?f=3 ... xml#p66304
ご連絡が遅くなってしまい申し訳ありませんでした。
クラス化してみたのですが初期化がおかしい様でエラーが取ることができません。
\multieditor\Form1.h(41) : error C2143: 構文エラー : ')' が ';' の前にありません。
また保存の仕方もよくわからないのですが宜しければソースを今一度みては頂けないでしょうか。
#pragma once
#define MAX 256;
namespace MultiEditor {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
// オリジナルクラス
ref class OBJECT_DATA{
String^ title;
String^ body;
};
/// <summary>
/// Form1 の概要
///
/// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた
/// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを
/// 変更する必要があります。この変更を行わないと、
/// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、
/// 正しく相互に利用できなくなります。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: ここにコンストラクタ コードを追加します
//
int index = -1;
stringData = gcnew array<OBJECT_DATA^>(MAX);
// 読み込み
System::IO::StreamReader^ sr =
gcnew System::IO::StreamReader("XML.txt",System::Text::Encoding::GetEncoding(932));
sr->ReadLine();
String^ Item;
while((Item = sr->ReadLine()) != nullptr){
String^ str = Item;
if(str->IndexOf("//") >= 0) index++;//->Substring(0,2)
// 値を挿入する
if( index != -1 ){
if( str->IndexOf("//") >= 0 ) this->listBoxTitle->Items->Add(Item->Replace("//",""));
else stringData->title[index] += Item + "\n";
}
}
sr->Close();
}
protected:
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ListBox^ listBoxTitle;
private: System::Windows::Forms::RichTextBox^ richTextBoxBody;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ ファイルFToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ menuSave;
private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
private: System::Windows::Forms::TextBox^ textBoxTitle;
private: System::Windows::Forms::Button^ buttonNew;
private: array<OBJECT_DATA^>^ stringData;
// 保存用の文字列を作成する
private: String^ SaveTextFileName(void){
return "aaa";
}
// データを保存する
private: void SaveTextFileName(String^ SaveString, String^ FileName){
System::IO::StreamWriter^ sw = gcnew System::IO::StreamWriter(FileName,false,System::Text::Encoding::GetEncoding(932)); // タブごとに確認
sw->Write(SaveString);
sw->Close();
}
protected:
protected:
private:
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
void InitializeComponent(void)
{
this->listBoxTitle = (gcnew System::Windows::Forms::ListBox());
this->richTextBoxBody = (gcnew System::Windows::Forms::RichTextBox());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->ファイルFToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->menuSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
this->textBoxTitle = (gcnew System::Windows::Forms::TextBox());
this->buttonNew = (gcnew System::Windows::Forms::Button());
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// listBoxTitle
//
this->listBoxTitle->FormattingEnabled = true;
this->listBoxTitle->HorizontalScrollbar = true;
this->listBoxTitle->ItemHeight = 12;
this->listBoxTitle->Location = System::Drawing::Point(12, 36);
this->listBoxTitle->Name = L"listBoxTitle";
this->listBoxTitle->Size = System::Drawing::Size(241, 376);
this->listBoxTitle->TabIndex = 0;
this->listBoxTitle->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::listBoxTitle_SelectedIndexChanged);
//
// richTextBoxBody
//
this->richTextBoxBody->Location = System::Drawing::Point(259, 59);
this->richTextBoxBody->Name = L"richTextBoxBody";
this->richTextBoxBody->Size = System::Drawing::Size(361, 377);
this->richTextBoxBody->TabIndex = 1;
this->richTextBoxBody->Text = L"";
this->richTextBoxBody->TextChanged += gcnew System::EventHandler(this, &Form1::richTextBoxBody_TextChanged);
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->ファイルFToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(632, 24);
this->menuStrip1->TabIndex = 2;
this->menuStrip1->Text = L"menuStrip1";
//
// ファイルFToolStripMenuItem
//
this->ファイルFToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->menuSave});
this->ファイルFToolStripMenuItem->Name = L"ファイルFToolStripMenuItem";
this->ファイルFToolStripMenuItem->Size = System::Drawing::Size(66, 20);
this->ファイルFToolStripMenuItem->Text = L"ファイル(&F)";
//
// menuSave
//
this->menuSave->Name = L"menuSave";
this->menuSave->Size = System::Drawing::Size(109, 22);
this->menuSave->Text = L"保存(&S)";
this->menuSave->Click += gcnew System::EventHandler(this, &Form1::menuSave_Click);
//
// saveFileDialog1
//
this->saveFileDialog1->Filter = L"テキストファイル(*.txt)|*.txt|すべてのファイル(*.*)|*.*";
//
// textBoxTitle
//
this->textBoxTitle->Location = System::Drawing::Point(259, 36);
this->textBoxTitle->Name = L"textBoxTitle";
this->textBoxTitle->Size = System::Drawing::Size(361, 19);
this->textBoxTitle->TabIndex = 3;
this->textBoxTitle->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxTitle_TextChanged);
//
// buttonNew
//
this->buttonNew->Location = System::Drawing::Point(12, 418);
this->buttonNew->Name = L"buttonNew";
this->buttonNew->Size = System::Drawing::Size(241, 23);
this->buttonNew->TabIndex = 4;
this->buttonNew->Text = L"新規追加";
this->buttonNew->UseVisualStyleBackColor = true;
this->buttonNew->Click += gcnew System::EventHandler(this, &Form1::buttonNew_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(632, 446);
this->Controls->Add(this->buttonNew);
this->Controls->Add(this->textBoxTitle);
this->Controls->Add(this->richTextBoxBody);
this->Controls->Add(this->listBoxTitle);
this->Controls->Add(this->menuStrip1);
this->KeyPreview = true;
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"MultiEditor";
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
// 保存を押したら
private: System::Void menuSave_Click(System::Object^ sender, System::EventArgs^ e) {
/*
String^ save = "";
for(int i=0; i<this->listBoxTitle->Items->Count; i++){
save += "//" + this->listBoxTitle->Items[i] + "\r\n" + body[i] + "\r\n";
}
if(saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK){
System::IO::StreamWriter^ sw = gcnew System::IO::StreamWriter(saveFileDialog1->FileName,false,System::Text::Encoding::GetEncoding(932));
sw->Write( save );
sw->Close();
}
*/
}
// リストボックス選択番号が変わったら
private: System::Void listBoxTitle_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
this->richTextBoxBody->Text = stringData[this->listBoxTitle->SelectedIndex];
this->textBoxTitle->Text = this->listBoxTitle->Text;
}
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
switch(e->KeyCode){
// アプリケーションの終了
case System::Windows::Forms::Keys::Escape:
Application::Exit();
break;
// リストボックスの削除
case System::Windows::Forms::Keys::Delete:
if( this->listBoxTitle->SelectedIndex != -1 )
this->listBoxTitle->Items->RemoveAt( this->listBoxTitle->SelectedIndex );
break;
}
// 新規追加
if (e->Control == true){
switch (e->KeyCode){
case System::Windows::Forms::Keys::N:
int i = this->listBoxTitle->SelectedIndex;
if( i != -1 ) this->listBoxTitle->Items[i] = i.ToString();
break;
}
}
}
private: System::Void textBoxTitle_TextChanged(System::Object^ sender, System::EventArgs^ e) {
int i = this->listBoxTitle->SelectedIndex;
if( i != -1 ) this->listBoxTitle->Items[i] = this->textBoxTitle->Text;
}
private: System::Void buttonNew_Click(System::Object^ sender, System::EventArgs^ e) {
this->listBoxTitle->Items->Add("New");
}
private: System::Void richTextBoxBody_TextChanged(System::Object^ sender, System::EventArgs^ e) {
stringData->body[this->listBoxTitle->SelectedIndex] = this->richTextBoxBody->Text;
}
};
}
// 0309 0630~0715