/********************************************************/
/*★ Source File を入力して ListBox に表示 前田 稔 ★*/
/********************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO; // for File, StreamReader
using System.Text; // for Encoding
public class MyForm : Form
{
private ListBox listBox1;
//public string file_name = "..\\..\\CSForm.cs";
public string file_name = "ListBoxFile.cs";
public MyForm()
{
InitializeComponent();
Load += new System.EventHandler(MyForm_Load);
}
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 15;
this.listBox1.Location = new System.Drawing.Point(12, 12);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(869, 229);
this.listBox1.TabIndex = 0;
//
// MyForm
//
this.ClientSize = new System.Drawing.Size(893, 256);
this.Controls.Add(this.listBox1);
this.Name = "MyForm";
this.ResumeLayout(false);
}
private void MyForm_Load(object sender, System.EventArgs e)
{ string str;
if (!File.Exists(file_name))
{ Console.WriteLine("ファイルが見つかりません {0}", file_name);
return;
}
StreamReader reader = new StreamReader(file_name,Encoding.GetEncoding("Shift_JIS"));
while((str=reader.ReadLine()) != null)
{
listBox1.Items.Add(str);
}
reader.Close();
}
}
class form01
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|