(1)からの続き
//ツールバーとステータスバーの作成
private void MakeBars()
{
//ToolStripクラスインスタンスの生成
this.toolStrip = new ToolStrip();
//ツールバーのレイアウトを一時停止
this.toolStrip.SuspendLayout();
//ToolStripButton配列を作成
this.tsButton = new ToolStripButton[10];
//本プログラムの埋め込みリソースのリソースマネージャーを作成
ResourceManager rm = new ResourceManager("IDList", myOwn);
//ツールバービットマップの読み込み
ImageList imgList = new ImageList();
imgList.ImageSize = new Size(16, 15);
imgList.Images.AddStrip((Bitmap)rm.GetObject("ToolBar"));
imgList.TransparentColor = Color.FromArgb(0xFF, 0xFF, 0xFF); //ToolBar.bmpの背景色
//ToolStripButton[0]を作成
this.tsButton[0] = new ToolStripButton();
this.tsButton[0].Text = "データを開く"; //テキスト設定
this.tsButton[0].Image = (Bitmap)imgList.Images[0]; //画像設定
this.tsButton[0].DisplayStyle = ToolStripItemDisplayStyle.Image; //画像表示のみ
this.tsButton[0].Click += OnOpen_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[0]); //ボタンを追加
//ToolStripButton[1]を作成
this.tsButton[1] = new ToolStripButton();
this.tsButton[1].Text = "データを保存"; //テキスト設定
this.tsButton[1].Image = (Bitmap)imgList.Images[1]; //画像設定
this.tsButton[1].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[1].Click += OnSave_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[1]); //ボタンを追加
//セパレーターを挿入
this.toolStrip.Items.Add(new ToolStripSeparator());
//ToolStripButton[2]を作成
this.tsButton[2] = new ToolStripButton();
this.tsButton[2].Text = "終了"; //テキスト設定
this.tsButton[2].Image = (Bitmap)imgList.Images[2]; //画像設定
this.tsButton[2].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[2].Click += OnExit_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[2]); //ボタンを追加
//セパレーターを挿入
this.toolStrip.Items.Add(new ToolStripSeparator());
//ToolStripButton[3]を作成
this.tsButton[3] = new ToolStripButton();
this.tsButton[3].Text = "追加"; //テキスト設定
this.tsButton[3].Image = (Bitmap)imgList.Images[3]; //画像設定
this.tsButton[3].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[3].Click += OnAdd_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[3]); //ボタンを追加
//ToolStripButton[4]を作成
this.tsButton[4] = new ToolStripButton();
this.tsButton[4].Text = "検索"; //テキスト設定
this.tsButton[4].Image = (Bitmap)imgList.Images[4]; //画像設定
this.tsButton[4].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[4].Click += OnSearch_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[4]); //ボタンを追加
//ToolStripButton[5]を作成
this.tsButton[5] = new ToolStripButton();
this.tsButton[5].Text = "編集"; //テキスト設定
this.tsButton[5].Image = (Bitmap)imgList.Images[5]; //画像設定
this.tsButton[5].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[5].Click += OnEdItem_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[5]); //ボタンを追加
//ToolStripButton[6]を作成
this.tsButton[6] = new ToolStripButton();
this.tsButton[6].Text = "削除"; //テキスト設定
this.tsButton[6].Image = (Bitmap)imgList.Images[6]; //画像設定
this.tsButton[6].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[6].Click += OnDelete_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[6]); //ボタンを追加
//セパレーターを挿入
this.toolStrip.Items.Add(new ToolStripSeparator());
//ToolStripButton[7]を作成
this.tsButton[7] = new ToolStripButton();
this.tsButton[7].Text = "並び替え"; //テキスト設定
this.tsButton[7].Image = (Bitmap)imgList.Images[7]; //画像設定
this.tsButton[7].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[7].Click += OnSort_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[7]); //ボタンを追加
//セパレーターを挿入
this.toolStrip.Items.Add(new ToolStripSeparator());
//ToolStripButton[8]を作成
this.tsButton[8] = new ToolStripButton();
this.tsButton[8].Text = "使い方"; //テキスト設定
this.tsButton[8].Image = (Bitmap)imgList.Images[8]; //画像設定
this.tsButton[8].DisplayStyle = ToolStripItemDisplayStyle.Image;//画像表示のみ
this.tsButton[8].Click += OnHowtoUse_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[8]); //ボタンを追加
//セパレーターを挿入
this.toolStrip.Items.Add(new ToolStripSeparator());
//ToolStripButton[9]を作成
this.tsButton[9] = new ToolStripButton();
this.tsButton[9].Text = "バージョン情報"; //テキスト設定
this.tsButton[9].Image = (Bitmap)imgList.Images[9]; //画像設定
this.tsButton[9].DisplayStyle = ToolStripItemDisplayStyle.Image; //画像表示のみ
this.tsButton[9].Click += OnVersion_Click; //Clickイベントハンドラ追加
this.toolStrip.Items.Add(this.tsButton[9]); //ボタンを追加
//ツールバーの設定
this.Controls.Add(this.toolStrip);
//ツールバーのレイアウトを再開
this.toolStrip.ResumeLayout(false);
this.toolStrip.PerformLayout();
//StatusStripクラスインスタンスの生成
this.statusStrip = new StatusStrip();
//ステータスバーにパネルとテキストを追加
tssl = new ToolStripStatusLabel[2];
tssl[0] = new ToolStripStatusLabel();
tssl[0].BorderSides = ToolStripStatusLabelBorderSides.All;
tssl[0].BorderStyle = Border3DStyle.SunkenInner;
tssl[0].BackColor = SystemColors.Control;
tssl[0].Text = "IDList for C# Ver. 1.0";
tssl[0].AutoSize = true;
tssl[0].TextAlign = ContentAlignment.MiddleLeft;
tssl[1] = new ToolStripStatusLabel();
tssl[1].BorderSides = ToolStripStatusLabelBorderSides.All;
tssl[1].BorderStyle = Border3DStyle.SunkenInner;
tssl[1].BackColor = SystemColors.Control;
tssl[1].TextAlign = ContentAlignment.MiddleLeft;
tssl[1].Text = "(ファイル名)";
tssl[1].ToolTipText = "(ファイル名)"; //ToolTip設定
tssl[1].Spring = true;
statusStrip.Items.AddRange(tssl);
statusStrip.ShowItemToolTips = true; //ToolTip表示
this.Controls.Add(this.statusStrip); //StatusStrip(ステータスバー)を追加
}
//終了処理
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
DialogResult dr = MessageBox.Show("終了しますか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(dr == DialogResult.No)
{
e.Cancel = true;
}
}
//「ファイルを開く」処理
private void OnOpen_Click(object sender, EventArgs e)
{
OpenFileDialog ofDlg = new OpenFileDialog();
//ファイルフィルターの指定
ofDlg.Filter = "データファイル|*.dat";
ofDlg.FilterIndex = 0;
ofDlg.RestoreDirectory = true; //初期ディレクトリへ復帰
ofDlg.CheckPathExists = true; //ファイルパスの存在チェック
ofDlg.InitialDirectory = ".\\IDListFiles"; // デフォルトのフォルダーの指定
ofDlg.Title = "ファイルを開く"; //ダイアログのタイトルを指定する
if(ofDlg.ShowDialog() == DialogResult.Cancel) //ダイアログを表示する
{
MessageBox.Show("キャンセルされました。", "キャンセル", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
bool flag;
if(MessageBox.Show("暗号化データファイルですか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
flag = true;
else
flag = false;
IDList.DataRead(ofDlg.FileName, flag); //解説:ファイル読み込み処理自体はIDListインスタンスが行います。
tssl[1].Text = ofDlg.FileName; //ファイル名を記録
tssl[1].ToolTipText = ofDlg.FileName; //ToolTip設定
}
//オブジェクトを破棄する
ofDlg.Dispose();
}
//「保存」処理
private void OnSave_Click(object sender, EventArgs e)
{
SaveFileDialog sfDlg = new SaveFileDialog();
//ファイルフィルターの指定
sfDlg.AddExtension = true; //拡張子自動付加
sfDlg.DefaultExt = ".dat";
sfDlg.Filter = "データファイル|*.dat";
sfDlg.FilterIndex = 0;
sfDlg.RestoreDirectory = true; //初期ディレクトリへ復帰
sfDlg.CheckPathExists = true; //ファイルパスの存在チェック
sfDlg.InitialDirectory = ".\\IDListFiles"; // デフォルトのフォルダーの指定
sfDlg.Title = "ファイルを保存"; //ダイアログのタイトルを指定する
sfDlg.OverwritePrompt = true; //上書き確認
if(sfDlg.ShowDialog() == DialogResult.Cancel) //ダイアログを表示する
{
MessageBox.Show("キャンセルされました。", "キャンセル", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
bool crptflag, hideflag; //解説:順に暗号化フラグ、隠しファイルフラグです。
if(MessageBox.Show("暗号化データファイルですか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
crptflag = true;
else
crptflag = false;
if(MessageBox.Show("隠しファイルにしますか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
hideflag = true;
else
hideflag = false;
IDList.DataWrite(sfDlg.FileName, crptflag, hideflag);
//ファイル名を記録
tssl[1].Text = sfDlg.FileName;
tssl[1].ToolTipText = sfDlg.FileName; //ToolTip設定
}
//オブジェクトを破棄する
sfDlg.Dispose();
}
//「終了」処理
private void OnExit_Click(object sender, EventArgs e)
{
Close(); //終了確認はOnClosingメソッドで行う
}
//「追加」処理
private void OnAdd_Click(object sender, EventArgs e)
{
IDList.Add(); //解説:実際の処理は全てIDListインスタンスでやります。
}
//「検索」処理
private void OnSearch_Click(object sender, EventArgs e)
{
IDList.Find(); //解説:実際の処理は全てIDListインスタンスでやります。
}
//「編集」処理
private void OnEdItem_Click(object sender, EventArgs e)
{
IDList.Edit(); //解説:実際の処理は全てIDListインスタンスでやります。
}
//「削除」処理
private void OnDelete_Click(object sender, EventArgs e)
{
IDList.Delete(); //解説:実際の処理は全てIDListインスタンスでやります。
}
//「並び替え」処理
private void OnSort_Click(object sender, EventArgs e)
{
IDList.Sort(); //解説:実際の処理は全てIDListインスタンスでやります。
}
//「使い方」処理
private void OnHowtoUse_Click(object sender, EventArgs e)
{
string str = ".\\HowToUse.txt";
using(StreamReader file = new StreamReader(str, Encoding.UTF8))
{
str = file.ReadToEnd();
file.Close(); //ファイルを閉じる
}
MessageBox.Show(str, "簡単な説明", MessageBoxButtons.OK, MessageBoxIcon.Information); //解説:メッセージボックス表示
Help.ShowHelp(this, "IDListHelp.chm"); //解説:HTMLHelpファイルの表示
System.Diagnostics.Process.Start(".\\IDList_CS使い方.html"); //解説:HTMLファイルの表示
}
//「バージョン」処理
private void OnVersion_Click(object sender, EventArgs e)
{
VersionDlg verDlg = new VersionDlg(this.Icon); //Versionダイアログ表示
verDlg.ShowDialog();
verDlg.Dispose();
}
}
/////////////////////
//Version ダイアログ
/////////////////////
class VersionDlg : Form
{
public VersionDlg(Icon ico)
{
//ダイアログの属性設定
this.Text = "バーション情報";
this.ClientSize = new Size(320, 100);
this.MaximizeBox = false; // 最大化ボタン
this.MinimizeBox = false; // 最小化ボタン
this.ShowInTaskbar = false; //タスクバー上表示
this.FormBorderStyle = FormBorderStyle.FixedDialog; // 境界のスタイル
this.StartPosition = FormStartPosition.CenterParent; // 親フォームの中央に配置
//コントロールの属性設定
Button btnOK = new Button();
btnOK.Size = new Size(40, 28);
btnOK.Location = new Point(ClientSize.Width - btnOK.Width - 10, (ClientSize.Height - btnOK.Height) / 2);
btnOK.Text = "OK";
btnOK.Click += new EventHandler(OnOK_Click);
Label imglabel = new Label();
imglabel.Size = new Size(40, 40);
imglabel.Location = new Point(10, (ClientSize.Height - imglabel.Height) / 2);
imglabel.BorderStyle = BorderStyle.Fixed3D;
imglabel.Image = ico.ToBitmap(); //親のシステムアイコン
Label label = new Label();
label.Size = new Size(ClientSize.Width - imglabel.Width - btnOK.Width - 40, ClientSize.Height- 20);
label.Location = new Point(imglabel.Width + 20, (ClientSize.Height - label.Height) / 2);
label.BorderStyle = BorderStyle.Fixed3D;
label.Text = "IDList for C# Version 1.0\r\nCopyright (c) 2026 by Ysama\r\n(written in Microsoft C#)";
label.TextAlign = ContentAlignment.MiddleCenter;
label.Font = new Font("Times New Roman", 10, FontStyle.Bold);
this.Controls.Add(btnOK);
this.Controls.Add(imglabel);
this.Controls.Add(label);
}
private void OnOK_Click(object sender, EventArgs e)
{
Close();
}
}
}
後はいよいよIDList_CS.cs(IDList_CS.dll)の解説だけとなりました。
