コメント |
@DIV
using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Sample_01
{
static class Program {
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Stream myStream;
OpenFileDialog dlg = new OpenFileDialog();
String[] arg = Environment.GetCommandLineArgs();
String delimStr = @"\";
Char[] delimiter = delimStr.ToCharArray();
String[] aData = arg[0].Split(delimiter);
String pgDir = String.Join(@"\", aData, 0, aData.Length - 1);
dlg.InitialDirectory = pgDir;
dlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dlg.FilterIndex = 2;
dlg.RestoreDirectory = true;
String str = "";
if ( dlg.ShowDialog() == DialogResult.OK ) {
myStream = dlg.OpenFile();
if (myStream != null) {
StreamReader sr = new StreamReader(
myStream,
Encoding.GetEncoding("Shift_JIS")
);
while ( sr.Peek() >= 0 ) {
str += sr.ReadLine() + "\r\n";
}
textBox1.Text = str;
sr.Close();
myStream.Close();
}
}
}
}
}
@END
[[Form1.Designer.cs]]
@DIV
namespace Sample_01
{
partial class Form1
{
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows フォーム デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(56, 28);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(180, 35);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(57, 97);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(551, 317);
this.textBox1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(665, 457);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
}
}
@END
|