入出力と描画の制御

SW を定義して、ブロックの入出力と描画の制御を行います。

前田稔の超初心者のプログラム入門

プログラムの説明

  1. MyHandler() で毎回再描画したのでは、修正したテキストが失われてしまいます。
    そこで Edit Object Class の pos が変更された時と文字コードが変更された時にだけ描画します。
    SW を定義して、ブロックの入出力と描画の制御を行います。
        int     SW = -1;
    
  2. class Edit に Set Get アクセッサを定義します。
        string  file_name;
        int     pos;
        string  code;
    
        // Set Get アクセッサ
        public int getpos
        {   get
            {   return pos;   }
        }
        public string char_code
        {   set
            {   code= value;  }
        }
        public string file
        {   get
            {   return file_name;  }
        }
    
  3. SW の情報によって描画する MyHandler() です。
    タイトルバーに現在描画中のファイル名を印字します。
        Edit    edit = new Edit();  // Edit Object Class の定義
        int     SW = -1;
    
        // Window を描画
        private void MyHandler(object sender, PaintEventArgs e)
        {
            if (SW==0)  return;
            if (SW==1)  edit.GetFile();
            textBox1.Text = edit.View();
            this.Text = edit.file;
            SW = 0;
        }
    
  4. FileOpen() では OpenFile(); で「ファイルのオープン&最初のブロックを入力」の後 SW を 2 に設定して下さい。
        private void FileOpen(object sender, EventArgs e)
        {
            edit.OpenFile();
            SW = 2;
            Invalidate();
        }
    
  5. テキストコードの選択でも edit.char_code にコードを設定して SW を 2 に設定します。
        private void utf16(object sender, EventArgs e)
        {
            edit.char_code = "utf-16";
            SW = 2;
            Invalidate();
        }
        private void utf8(object sender, EventArgs e)
        {
            edit.char_code = "utf-8";
            SW = 2;
            Invalidate();
        }
        private void jis(object sender, EventArgs e)
        {
            edit.char_code = "Shift_JIS";
            SW = 2;
            Invalidate();
        }
        private void none(object sender, EventArgs e)
        {
            edit.code = string.Empty;
            SW = 2;
            Invalidate();
        }
    
  6. プログラム(この段階では Binary Viewer)を実行して、表示を確認して下さい。

[Next Chapter ↓] ページを修正
[Previous Chapter ↑] Binary Editor のメニューを設定

超初心者のプログラム入門(C# Frame Work)