2013年3月8日金曜日

Pictures Slide Viewer に機能追加

前回作成した Pictures Slide Viewer に
リストの項目ごとの削除機能
リスト項目とスライド時間を終了時保存し、次回起動時に呼び出す機能
を追加しました。

リスト項目の保存、呼び出しは Properties.Settings を利用し
リスト項目をカンマ区切りのベタテキストで保存し、
読み込み時にカンマで分割し直しています。




PicturesSlideViewer.exe  C#  WinDesktop

前回から、終了方法を変更
リストから項目ごとに削除、設定読み込み、設定保存、を追加

Form1.cs
=====================================================================




        // 終了
        private void button2_Click(object sender, EventArgs e)
        {
            // Environment.Exit(0);
            this.Close();
        }
 

        // リストから項目ごとに削除
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            if ((listBox1.Items.Count > 0) && (listBox1.SelectedIndex >= 0))
            {
                DialogResult result = MessageBox.Show(listBox1.Text, "リストから削除します", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    int selInd = listBox1.SelectedIndex;
                    // リストの中から削除します
                    listBox1.Items.RemoveAt(selInd);

                    // リスト選択項目指定
                    if (listBox1.Items.Count > 0)
                    {
                        if (listBox1.Items.Count > selInd)
                        {
                            listBox1.SetSelected(selInd, true);
                        }
                        else
                        {
                            listBox1.SetSelected(selInd -1 , true);
                        }
                    }
                }
            }
        }

        // 設定読み込み
        private void Form1_Load(object sender, EventArgs e)
        {
            numericUpDown1.Value = Properties.Settings.Default.SetNum;

            String StrSett = Properties.Settings.Default.Setting;
 
            // 分割して配列に格納する
            string[] stArrayData = StrSett.Split(',');
            // データを追加する
            foreach (string stData in stArrayData)
            {
                if (stData != "")
                {
                    listBox1.Items.Add(stData);
                }
            }
            // リストの1番を選択
            if (listBox1.Items.Count > 0)
            {
                // ListSet();
                listBox1.SetSelected(0, true);
            }

        }

        // 設定保存
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            // スライド時間設定保存
            int Setnum = Convert.ToInt32(numericUpDown1.Value);
            Properties.Settings.Default.SetNum = Setnum;
            // リスト保存
            if (listBox1.Items.Count > 0)
            {
                string StrSett = string.Empty;
             
                for (int i = 0; i < listBox1.Items.Count; ++i)
                {
                    listBox1.SetSelected(i, true);
                    StrSett = StrSett + listBox1.Text + ",";
                }

                Properties.Settings.Default.Setting = StrSett;          
            }
            else
            {
                Properties.Settings.Default.Setting = null;
            }

            Properties.Settings.Default.Save();
         
        }
=====================================================================




0 件のコメント:

コメントを投稿