私が理解していることから、特定のディレクトリ内のファイルを繰り返し処理し、リストボックスでダブルクリックして開いたら編集できるようにしたいと考えています。
これは、var Files = Directory.GetFiles("path", ".txt");
Files
ファイルstring[]
名の
次に、リストボックスに次のようなファイルを入力します。
ListBox lbx = new ListBox();
lbx.Size = new System.Drawing.Size(X,Y); //Set to desired Size.
lbx.Location = new System.Drawing.Point(X,Y); //Set to desired Location.
this.Controls.Add(listBox1); //Add to the window control list.
lbx.DoubleClick += OpenFileandBeginEditingDelegate;
lbx.BeginUpdate();
for(int i = 0; i < numfiles; i++)
lbx.Items.Add(Files[i]);
lbx.EndUpdate();
これで、イベント デリゲートは次のようになります。
OpenFileandBeginEditingDelegate(object sender, EventArgs e)
{
string file = lbx.SelectedItem.ToString();
FileStream fs = new FileStream(Path + file, FileMode.Open);
//Now add this to the textbox
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
tbx.Text += temp.GetString(b);//tbx being the textbox you want to use as the editor.
}
}
VS ウィンドウ エディターを介してイベント ハンドラーを追加するには、対象のコントロールをクリックし、そのコントロールのプロパティ ペインに移動します。DoubleClick
次に、イベント ペインに切り替えて、デザイナーが有効なデリゲート シグネチャを自動挿入し、イベントのロジックを記述できるようにする必要がある場合は、イベントが見つかるまでスクロールする必要があります。