概要
cscの作法、調べてみた。
ファイルダイアログやってみた。
サンプルコード
using System;
using System.Windows.Forms;
using System.Drawing;
class form1: Form {
form1() {
Text = "open";
ClientSize = new Size(200, 200);
Button btn1 = new Button();
btn1.Location = new Point(50, 50);
btn1.Text = "test";
btn1.Click += btn1_Click;
Controls.AddRange(new Control[] {
btn1
});
}
void btn1_Click(object sender, System.EventArgs e) {
string fileContent = string.Empty;
string filePath = string.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "c:\\";
openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
MessageBox.Show(filePath);
}
}
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
以上。