
| 親メニュー | 子メニュー | メソッド | 説明 |
|---|---|---|---|
| 検索(&S) | |||
| キー(&K) | KeyType | 検索(置き換)キーをタイプします | |
| タイトル(&T) | TSearch | タイトルを検索します | |
| テキスト検索(&S) | Search | TEXT を検索します | |
| 置き換え(&R) | Replace | TEXT を置き換えます |

int m_Idx; // Table Index
string m_str; // Node 選択文字列
bool m_UP = false; // ファイル更新フラグ
string m_sou = "Source"; // 検索キー(パスワード)
string m_des = "Destinate"; // 置き換え文字列
string m_file = "C:\\TMP\\Test2.mem";
|
// アプリケーションの初期化
private void MyForm_Load(object sender, System.EventArgs e)
{
ReadFile(m_file);
this.Text = m_file;
button1.Hide();
textBox1.Hide();
textBox2.Hide();
m_Idx = 0;
treeView1.TopNode.Expand();
richTextBox1.Text = (string)t_txt[0];
}
|
private void KeyType(object sender, EventArgs e)
{
richTextBox1.Hide();
button1.Show();
textBox1.Show();
textBox2.Show();
}
|
private void button_Click(object sender, EventArgs e)
{
m_sou = textBox1.Text;
m_des = textBox2.Text;
button1.Hide();
textBox1.Hide();
textBox2.Hide();
richTextBox1.Show();
}
|
// Node のルートを Text に表示する
private void FormView(TreeNode pnode)
{
TreeNode node;
string str = "";
int i;
for (node = pnode; node != null; node = node.Parent)
{
for (i = 0; i < t_node.Count && (TreeNode)t_node[i] != node; i++) ;
if (i >= t_node.Count) break;
str = t_ttl[i] + "/" + str;
}
this.Text = str;
treeView1.Select();
}
|
private void FormView(string str, string key)
{
int pos;
richTextBox1.Text = str;
richTextBox1.Select(0, richTextBox1.Text.Length);
richTextBox1.SelectionColor = Color.Black;
Title.Text = (string)t_ttl[m_Idx] + "(" + (string)t_ymd[m_Idx] + ")";
for (pos = 0; ; )
{
pos = richTextBox1.Find(key, pos, RichTextBoxFinds.None);
if (pos < 0) break;
richTextBox1.SelectionColor = Color.DarkMagenta;
pos++;
}
richTextBox1.Modified = false;
}
|
private void TSearch(object sender, EventArgs e)
{ SearchMenu(0); }
private void Search(object sender, EventArgs e)
{ SearchMenu(1); }
private void Replace(object sender, EventArgs e)
{ SearchMenu(2); }
|
private void SearchMenu(int val)
{
m_Idx = 0;
richTextBox1.Text = (string)t_txt[m_Idx];
treeView1.SelectedNode = (TreeNode)t_node[m_Idx];
switch(val)
{
case 0: TNext(m_sou); break;
case 1: Next(m_sou); break;
case 2: Next(m_sou, m_des); break;
}
MessageBox.Show("☆検索(置換)が終わりました", "Search");
if (m_Idx >= t_node.Count) m_Idx = 0;
Title.Text = (string)t_ttl[m_Idx] + "(" + (string)t_ymd[m_Idx] + ")";
FormView((TreeNode)t_node[m_Idx]);
treeView1.SelectedNode = (TreeNode)t_node[m_Idx];
if (val>0) FormView((string)t_txt[m_Idx], m_sou);
treeView1.Select();
}
|
private void TNext(string sou)
{
string str;
DialogResult rc;
for (; m_Idx < t_ttl.Count; m_Idx++)
{
str = (string)t_ttl[m_Idx];
if (str.IndexOf(sou, StringComparison.OrdinalIgnoreCase) >= 0)
{
richTextBox1.Text = (string)t_txt[m_Idx];
Title.Text = (string)t_ttl[m_Idx] + "(" + (string)t_ymd[m_Idx] + ")";
FormView((TreeNode)t_node[m_Idx]);
rc = MessageBox.Show("続けますか?", "選択",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rc == DialogResult.No) return;
}
}
}
|
private void Next(string sou)
{
string str;
for (; m_Idx < t_txt.Count; m_Idx++)
{
str = (string)t_txt[m_Idx];
if (str.IndexOf(sou, StringComparison.OrdinalIgnoreCase) >= 0)
{ if (!KeySelct(str, sou)) return; }
}
m_Idx = 0;
}
|
private void Next(string sou, string des)
{
string str;
int pos;
for (; m_Idx < t_txt.Count; m_Idx++)
{
str = (string)t_txt[m_Idx];
if (str.IndexOf(sou, StringComparison.OrdinalIgnoreCase) >= 0)
{
richTextBox1.Text = (string)t_txt[m_Idx];
for (pos = 0; ; )
{
pos = richTextBox1.Find(sou, pos, RichTextBoxFinds.None);
if (pos < 0) break;
richTextBox1.SelectedText = des;
pos += des.Length;
}
str = richTextBox1.Text;
t_txt[m_Idx] = str;
m_UP = true;
if (!KeySelct(str, des)) return;
}
}
}
|
// RichTextBox に str を設定して key の色を変えて表示
private bool KeySelct(string str, string key)
{
DialogResult rc;
FormView(str, key);
FormView((TreeNode)t_node[m_Idx]);
rc = MessageBox.Show("続けますか?", "選択",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (rc == DialogResult.Yes) return true;
return false;
}
|

[Next Chapter ↓] ToolStrip を実装
[Previous Chapter ↑] File Menu