
| 親メニュー | 子メニュー | メソッド | 説明 |
|---|---|---|---|
| ファイル(&F) | |||
| ファイルを開く(&O) | Open | Memo ファイルをオープンします | |
| 上書き保存(&S) | Save | ファイルを上書き保存します | |
| 別名で保存(&A) | SaveAT | ファイルを別名で保存します | |
| 新規ファイル(&N) | NewFile | 新規ファイルを作成します | |
| 終了(&X) | Exit | プログラムを終了します |
int m_Idx; // Table Index
bool m_UP = false; // ファイル更新フラグ
string m_file = "C:\\TMP\\Test2.mem";
// アプリケーションの初期化
private void MyForm_Load(object sender, System.EventArgs e)
{
ReadFile(m_file);
m_Idx = 0;
treeView1.TopNode.Expand();
richTextBox1.Text = (string)t_txt[0];
this.Text = m_file;
}
|
//☆ ファイルメニュー
private void Open(object sender, EventArgs e)
{
DialogResult rc;
CheckText();
if (m_UP)
{
rc = MessageBox.Show("保存しないで実行?", "選択", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rc == DialogResult.No) return;
}
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "MEMO ファイルを選択してください";
openFileDialog1.Filter = "MEMO FILE|*.mem|すべてのファイル|*.*";
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
m_file = openFileDialog1.FileName;
ReadFile(m_file);
}
openFileDialog1.Dispose();
m_UP = false;
richTextBox1.Modified = false;
this.Text = m_file;
m_Idx = 0;
richTextBox1.Text = (string)t_txt[m_Idx];
treeView1.TopNode.Expand();
}
|
class form01
{
[STAThread]
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|
private void NewFile(object sender, EventArgs e)
{
DialogResult rc;
CheckText();
if (m_UP)
{
rc = MessageBox.Show("保存しないで実行?", "選択", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rc == DialogResult.No) return;
}
string str = DateTime.Now.ToString();
str = str.Substring(0,10) + ":" + str.Substring(0,10);
t_lev.Clear();
t_ttl.Clear();
t_ymd.Clear();
t_txt.Clear();
t_lev.Add(2);
t_ttl.Add("新規ファイル");
t_ymd.Add(str);
t_txt.Add("新規データ\n");
t_lev.Add(2);
t_ttl.Add("ごみ箱");
t_ymd.Add(str);
t_txt.Add("ごみ箱\n");
t_node.Clear();
treeView1.Nodes.Clear();
m_Idx = 0;
Set_TVFunc(treeView1, 2);
m_Idx = 0;
richTextBox1.Text = (string)t_txt[0];
treeView1.ExpandAll();
m_UP = false;
richTextBox1.Modified = false;
m_file = "c:\\tmp\\New.mem";
this.Text = m_file;
}
|
private void Save(object sender, EventArgs e)
{
CheckText();
string str = m_file;
int i = str.LastIndexOf('\\');
if (i>0) str = str.Substring(0,i) + "\\$memo.mem";
else str = "$memo.mem";
System.IO.File.Delete(str);
System.IO.File.Move(m_file, str);
m_str = "";
TreeNode node;
for(node=(TreeNode)t_node[0]; node!=null; node=node.NextNode)
{ Get_TVFunc(node, 2); }
StreamWriter writer = new StreamWriter(m_file, false, Encoding.UTF8);
writer.Write(m_str);
writer.Close();
m_UP = false;
richTextBox1.Modified = false;
this.Text = m_file;
}
|
private void SaveAT(object sender, EventArgs e)
{
CheckText();
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Title = "保存するファイルを選択してください";
saveFileDialog1.Filter = "Memo File|*.mem|すべてのファイル|*.*";
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{
m_file = saveFileDialog1.FileName;
m_str = "";
TreeNode node;
for(node=(TreeNode)t_node[0]; node!=null; node=node.NextNode)
{ Get_TVFunc(node, 2); }
StreamWriter writer = new StreamWriter(m_file,false,Encoding.UTF8);
writer.Write(m_str);
writer.Close();
m_UP = false;
richTextBox1.Modified = false;
this.Text = m_file;
}
}
|
[Next Chapter ↓] Search Menu
[Previous Chapter ↑] Tree Menu