close

#pragma once


namespace ex1
{
 using namespace System;
 using namespace System::ComponentModel;
 using namespace System::Collections;
 using namespace System::Windows::Forms;
 using namespace System::Data;
 using namespace System::Drawing;

 ///


 /// Form1 的摘要
 ///
 /// 警告: 如果您變更這個類別的名稱,就必須變更與這個類別所依據之所有 .resx 檔案關聯的
 /// Managed 資源編譯器工具的 'Resource File Name' 屬性。
 /// 否則,這些設計工具將無法與這個表單關聯的當地語系化資源正確互動。
 ///

 public __gc class Form1 : public System::Windows::Forms::Form
 {
 public:
  Form1(void)
  {
   InitializeComponent();
  }
 
 protected:
  void Dispose(Boolean disposing)
  {
   if (disposing && components)
   {
    components->Dispose();
   }
   __super::Dispose(disposing);
  }
 private: System::Windows::Forms::MainMenu *  mainMenu1;
 private: System::Windows::Forms::MenuItem *  mmuFile;
 private: System::Windows::Forms::MenuItem *  mmuNew;
 private: System::Windows::Forms::MenuItem *  mmuOpen;
 private: System::Windows::Forms::MenuItem *  mmuSave;
 private: System::Windows::Forms::MenuItem *  mmuSaveAs;
 private: System::Windows::Forms::MenuItem *  menuItem6;
 private: System::Windows::Forms::MenuItem *  mmuEnd;
 private: System::Windows::Forms::MenuItem *  mmuItem;
 private: System::Windows::Forms::MenuItem *  mmuCancel;
 private: System::Windows::Forms::MenuItem *  mmuSet;
 private: System::Windows::Forms::MenuItem *  mmuFomat;
 private: System::Windows::Forms::MenuItem *  mmuFont;
 private: System::Windows::Forms::MenuItem *  mmuColor;
 private: System::Windows::Forms::RichTextBox *  richTextBox1;
 private: System::Windows::Forms::ContextMenu *  contextMenu1;
 private: System::Windows::Forms::FontDialog *  fontDialog1;
 private: System::Windows::Forms::ColorDialog *  colorDialog1;
 private: System::Windows::Forms::MenuItem *  mmuFColor;
 private: System::Windows::Forms::MenuItem *  mmuBColor;
 private: System::Windows::Forms::MenuItem *  ctmCpy;
 private: System::Windows::Forms::MenuItem *  ctmPaste;
 private: System::Windows::Forms::MenuItem *  ctmCut;
 private: System::Windows::Forms::OpenFileDialog *  openFileDialog1;
 private: System::Windows::Forms::SaveFileDialog *  saveFileDialog1;

 private:
  ///


  /// 設計工具所需的變數。
  ///

  System::ComponentModel::Container * components;

  ///


  /// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
  /// 這個方法的內容。
  ///

  void InitializeComponent(void)
  {
   this->mainMenu1 = new System::Windows::Forms::MainMenu();
   this->mmuFile = new System::Windows::Forms::MenuItem();
   this->mmuNew = new System::Windows::Forms::MenuItem();
   this->mmuOpen = new System::Windows::Forms::MenuItem();
   this->mmuSave = new System::Windows::Forms::MenuItem();
   this->mmuSaveAs = new System::Windows::Forms::MenuItem();
   this->menuItem6 = new System::Windows::Forms::MenuItem();
   this->mmuEnd = new System::Windows::Forms::MenuItem();
   this->mmuItem = new System::Windows::Forms::MenuItem();
   this->mmuCancel = new System::Windows::Forms::MenuItem();
   this->mmuSet = new System::Windows::Forms::MenuItem();
   this->mmuFomat = new System::Windows::Forms::MenuItem();
   this->mmuFont = new System::Windows::Forms::MenuItem();
   this->mmuColor = new System::Windows::Forms::MenuItem();
   this->mmuFColor = new System::Windows::Forms::MenuItem();
   this->mmuBColor = new System::Windows::Forms::MenuItem();
   this->richTextBox1 = new System::Windows::Forms::RichTextBox();
   this->contextMenu1 = new System::Windows::Forms::ContextMenu();
   this->ctmCpy = new System::Windows::Forms::MenuItem();
   this->ctmPaste = new System::Windows::Forms::MenuItem();
   this->ctmCut = new System::Windows::Forms::MenuItem();
   this->fontDialog1 = new System::Windows::Forms::FontDialog();
   this->colorDialog1 = new System::Windows::Forms::ColorDialog();
   this->openFileDialog1 = new System::Windows::Forms::OpenFileDialog();
   this->saveFileDialog1 = new System::Windows::Forms::SaveFileDialog();
   this->SuspendLayout();
   //
   // mainMenu1
   //
   System::Windows::Forms::MenuItem* __mcTemp__1[] = new System::Windows::Forms::MenuItem*[3];
   __mcTemp__1[0] = this->mmuFile;
   __mcTemp__1[1] = this->mmuItem;
   __mcTemp__1[2] = this->mmuFomat;
   this->mainMenu1->MenuItems->AddRange(__mcTemp__1);
   //
   // mmuFile
   //
   this->mmuFile->Index = 0;
   System::Windows::Forms::MenuItem* __mcTemp__2[] = new System::Windows::Forms::MenuItem*[6];
   __mcTemp__2[0] = this->mmuNew;
   __mcTemp__2[1] = this->mmuOpen;
   __mcTemp__2[2] = this->mmuSave;
   __mcTemp__2[3] = this->mmuSaveAs;
   __mcTemp__2[4] = this->menuItem6;
   __mcTemp__2[5] = this->mmuEnd;
   this->mmuFile->MenuItems->AddRange(__mcTemp__2);
   this->mmuFile->Text = S"File(&F)";
   //
   // mmuNew
   //
   this->mmuNew->Index = 0;
   this->mmuNew->Text = S"New(&N)";
   this->mmuNew->Click += new System::EventHandler(this, mmuNew_Click_1);
   //
   // mmuOpen
   //
   this->mmuOpen->Index = 1;
   this->mmuOpen->Text = S"Open(&O)";
   this->mmuOpen->Click += new System::EventHandler(this, mmuOpen_Click_1);
   //
   // mmuSave
   //
   this->mmuSave->Index = 2;
   this->mmuSave->Text = S"Save(&S)";
   this->mmuSave->Click += new System::EventHandler(this, mmuSave_Click_1);
   //
   // mmuSaveAs
   //
   this->mmuSaveAs->Index = 3;
   this->mmuSaveAs->Text = S"SaveAs(&A)";
   this->mmuSaveAs->Click += new System::EventHandler(this, mmuSaveAs_Click_1);
   //
   // menuItem6
   //
   this->menuItem6->Index = 4;
   this->menuItem6->Text = S"-";
   //
   // mmuEnd
   //
   this->mmuEnd->Index = 5;
   this->mmuEnd->Text = S"Exit(&X)";
   this->mmuEnd->Click += new System::EventHandler(this, mmuEnd_Click_1);
   //
   // mmuItem
   //
   this->mmuItem->Index = 1;
   System::Windows::Forms::MenuItem* __mcTemp__3[] = new System::Windows::Forms::MenuItem*[2];
   __mcTemp__3[0] = this->mmuCancel;
   __mcTemp__3[1] = this->mmuSet;
   this->mmuItem->MenuItems->AddRange(__mcTemp__3);
   this->mmuItem->Text = S"Item(&I)";
   //
   // mmuCancel
   //
   this->mmuCancel->Index = 0;
   this->mmuCancel->Text = S"Cancel(&C)";
   this->mmuCancel->Click += new System::EventHandler(this, mmuCancel_Click);
   //
   // mmuSet
   //
   this->mmuSet->Index = 1;
   this->mmuSet->Text = S"Set(&S)";
   this->mmuSet->Click += new System::EventHandler(this, mmuSet_Click);
   //
   // mmuFomat
   //
   this->mmuFomat->Index = 2;
   System::Windows::Forms::MenuItem* __mcTemp__4[] = new System::Windows::Forms::MenuItem*[2];
   __mcTemp__4[0] = this->mmuFont;
   __mcTemp__4[1] = this->mmuColor;
   this->mmuFomat->MenuItems->AddRange(__mcTemp__4);
   this->mmuFomat->Text = S"Fomat(&O)";
   //
   // mmuFont
   //
   this->mmuFont->Index = 0;
   this->mmuFont->Text = S"Font(&F)";
   this->mmuFont->Click += new System::EventHandler(this, mmuFont_Click);
   //
   // mmuColor
   //
   this->mmuColor->Index = 1;
   System::Windows::Forms::MenuItem* __mcTemp__5[] = new System::Windows::Forms::MenuItem*[2];
   __mcTemp__5[0] = this->mmuFColor;
   __mcTemp__5[1] = this->mmuBColor;
   this->mmuColor->MenuItems->AddRange(__mcTemp__5);
   this->mmuColor->Text = S"Color(&C)";
   //
   // mmuFColor
   //
   this->mmuFColor->Index = 0;
   this->mmuFColor->Text = S"FirstColor";
   this->mmuFColor->Click += new System::EventHandler(this, mmuFColor_Click);
   //
   // mmuBColor
   //
   this->mmuBColor->Index = 1;
   this->mmuBColor->Text = S"BackColor";
   this->mmuBColor->Click += new System::EventHandler(this, mmuBColor_Click);
   //
   // richTextBox1
   //
   this->richTextBox1->ContextMenu = this->contextMenu1;
   this->richTextBox1->Location = System::Drawing::Point(16, 18);
   this->richTextBox1->Name = S"richTextBox1";
   this->richTextBox1->Size = System::Drawing::Size(232, 268);
   this->richTextBox1->TabIndex = 0;
   this->richTextBox1->Text = S"";
   //
   // contextMenu1
   //
   System::Windows::Forms::MenuItem* __mcTemp__6[] = new System::Windows::Forms::MenuItem*[3];
   __mcTemp__6[0] = this->ctmCpy;
   __mcTemp__6[1] = this->ctmPaste;
   __mcTemp__6[2] = this->ctmCut;
   this->contextMenu1->MenuItems->AddRange(__mcTemp__6);
   //
   // ctmCpy
   //
   this->ctmCpy->Index = 0;
   this->ctmCpy->Text = S"Copy";
   this->ctmCpy->Click += new System::EventHandler(this, ctmCpy_Click);
   //
   // ctmPaste
   //
   this->ctmPaste->Index = 1;
   this->ctmPaste->Text = S"Paste";
   this->ctmPaste->Click += new System::EventHandler(this, ctmPaste_Click);
   //
   // ctmCut
   //
   this->ctmCut->Index = 2;
   this->ctmCut->Text = S"Cut";
   this->ctmCut->Click += new System::EventHandler(this, ctmCut_Click);
   //
   // Form1
   //
   this->AutoScaleBaseSize = System::Drawing::Size(5, 15);
   this->ClientSize = System::Drawing::Size(292, 293);
   this->Controls->Add(this->richTextBox1);
   this->Menu = this->mainMenu1;
   this->Name = S"Form1";
   this->Text = S"Form1";
   this->Load += new System::EventHandler(this, Form1_Load);
   this->ResumeLayout(false);

  }

 
  String *fileName;

 

 private: System::Void mmuCancel_Click(System::Object *  sender, System::EventArgs *  e)
    {
     richTextBox1->SelectionBullet=false; 
    }

private: System::Void mmuSet_Click(System::Object *  sender, System::EventArgs *  e)
   {
    richTextBox1->SelectionBullet=true;
   }


private: System::Void mmuFont_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(fontDialog1->ShowDialog()==DialogResult::OK)
  richTextBox1->SelectionFont=fontDialog1->Font;
   }

private: System::Void mmuFColor_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(colorDialog1->ShowDialog()==DialogResult::OK)
  richTextBox1->SelectionColor=colorDialog1->Color;
   }


private: System::Void mmuBColor_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(colorDialog1->ShowDialog()==DialogResult::OK)
  richTextBox1->BackColor=colorDialog1->Color;

   }


private: System::Void ctmCpy_Click(System::Object *  sender, System::EventArgs *  e)
   {
    richTextBox1->Copy();

   }

private: System::Void ctmPaste_Click(System::Object *  sender, System::EventArgs *  e)
   {
    richTextBox1->Paste();

   }

private: System::Void ctmCut_Click(System::Object *  sender, System::EventArgs *  e)
   {
    richTextBox1->Cut();

   }

private: System::Void mmuNew_Click_1(System::Object *  sender, System::EventArgs *  e)
   {
    Form1_Load(sender,e);
   }


private: System::Void mmuOpen_Click_1(System::Object *  sender, System::EventArgs *  e)
   {
     openFileDialog1->Filter="文字檔 (*.txt)|*.txt|所有檔案 (*.*)|*.*";
     openFileDialog1->FilterIndex=1;
     openFileDialog1->RestoreDirectory=true;
     openFileDialog1->DefaultExt=".txt";
     if(openFileDialog1->ShowDialog()==DialogResult::OK)
     {
         fileName=openFileDialog1->FileName;
         richTextBox1->LoadFile(openFileDialog1->FileName,RichTextBoxStreamType::PlainText);
     }
   }

private: System::Void mmuSave_Click_1(System::Object *  sender, System::EventArgs *  e)
   {
   if(String::Compare(fileName, "")==0)
     {
         mmuSaveAs_Click_1(sender,e);
         return ;
     }
     System::IO::StreamWriter *sw=new System::IO::StreamWriter (saveFileDialog1->FileName,false,System::Text::Encoding::Default);
     sw->Write(richTextBox1->Text);
     sw->Close();
   }

private: System::Void mmuSaveAs_Click_1(System::Object *  sender, System::EventArgs *  e)
   {
   saveFileDialog1->Filter="文字檔 (*.txt)|*.txt|所有檔案 (*.*)|*.*";
     saveFileDialog1->FilterIndex=1;
     saveFileDialog1->RestoreDirectory=true;
     saveFileDialog1->DefaultExt=".txt";
     if(saveFileDialog1->ShowDialog()==DialogResult::OK)
     {
         System::IO::StreamWriter *sw=new System::IO::StreamWriter (saveFileDialog1->FileName,false,System::Text::Encoding::Default);
         sw->Write(richTextBox1->Text);
         sw->Close();
         this->Text=String::Concat(fileName,"-記事本");
     }
   }

private: System::Void mmuEnd_Click_1(System::Object *  sender, System::EventArgs *  e)
   {
    exit(0);
   }

private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
   {
            richTextBox1->Text="";
     fileName="";
     this->Text="未命名-記事本";
   }

};
}


arrow
arrow
    全站熱搜

    mitia 發表在 痞客邦 留言(0) 人氣()