お早うございます。zen73です。皆さんからのアドバイスとご指導により,いま作っているアプリもようやく完成に近づいてきました。このことについてまずお礼申します。
Application.Restart();
で,アプリケーションを再起動したときに
「メニューフォーム」が画面に表示されずに
タスクバーに「アイコン」が表示された状態になっています。
(画面表示されているのは自分のコード)
それで以下のことを試してみました。
----------Form1-----------------------------------------------
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
}
----------Form2-----------------------------------------------
private void button1_Click(object sender, EventArgs e)
{
Application.Restart();
}
この場合に再起動したとき,Form1が画面に表示されています。
(しかし,何回か試しているとき,上と同様の状態になってしまうこともありますが意識して再現させることはできません)
実際の場面は,下のよう(整理せず,そのままで申し訳ないのですが)になっています。
*「スプラッシュウィンドウ」や「ディスプレイへのフル表示」が不具合を起こすのかなと思い,確かめてみましたがこれが原因ではないようです。
--------------------------------------------------------------------------------------------------------
private void frm0Menu_Load(object sender, EventArgs e)
{
//データを 'suitoDataSet.code' テーブルに読み込みます。
this.codeTableAdapter.Fill(this.suitoDataSet.code);
//SplashWindowを表示する
frm0Splash fs = new frm0Splash();
fs.Show();
fs.Refresh();
Thread.Sleep(2000); //2000ms 一時停止
fs.Close();
fs.Dispose();
//DBTable_codeを読み込む
read_code();
//ボタンコントロール配列を作成
this.btnArray = new Button[13];
//ボタンコントロールの配列に代入
this.btnArray[0] = this.btnEnd;
this.btnArray[1] = this.btnInp;
this.btnArray[2] = this.btnSuito;
this.btnArray[3] = this.btnKeihi;
this.btnArray[4] = this.btnJokyo;
this.btnArray[5] = this.btnKessan;
this.btnArray[ 6] = this.btnYosan;
this.btnArray[7] = this.btnTeisei;
this.btnArray[ 8] = this.btnHensei;
this.btnArray[9] = this.btnSinnen;
this.btnArray[10] = this.btnKomoku;
this.btnArray[11] = this.btnKosin;
this.btnArray[12] = this.btnYosanB;
//イベントハンドラに関連付け
for (int i = 0; i < this.btnArray.Length; i++)
{
this.btnArray[ i].Click += new System.EventHandler(this.btnArray_Click);
this.btnArray[ i].MouseLeave += new System.EventHandler(this.btnArray_MouseLeave);
this.btnArray[ i].MouseEnter += new System.EventHandler(this.btnArray_MouseEnter);
}
//フォームの大きさを画面の解像度に合わせる
this.Width = Screen.GetWorkingArea(this).Width - 20;
this.Height = Screen.GetWorkingArea(this).Height - 20;
//画面全体の大きさを取得。
int screenw, screenh;
screenw = Screen.PrimaryScreen.WorkingArea.Width; //画面の幅
screenh = Screen.PrimaryScreen.WorkingArea.Height; //画面の高さ
//Formの中央位置を計算
this.Left = (screenw - this.Width) / 2; //フォーム左端位置
this.Top = (screenh - this.Height) / 2; //フォーム上端位置
//panel1を中央に配置
panel1.Left = (this.ClientSize.Width - panel1.Width) / 2; // 左右中央
panel1.Top = (this.ClientSize.Height - panel1.Height) / 2; // 上下中央
}
----------------------