コード例 #1
0
        // 関数:ListBoxの選択アイテムのリネーム
        public void ListReName()
        {
            // アイテムを何も選択していない場合はメッセージを表示
            if (listBox1.SelectedIndex == -1)
            {
                MessageBox.Show("リストを選択してください");
                return;
            }

            // ListBoxの選択Indexが変化した時のイベントをここでOFFにする
            listBox1.SelectedIndexChanged -= listBox1_SelectedIndexChanged;

            // ListBoxの選択アイテムの名前を取得
            lbSelName = listBox1.SelectedItem.ToString();
            // ListBoxの選択アイテムのindexを取得
            lbSelId = listBox1.SelectedIndex;

            // リネームダイアログを開く
            FormReName f = new FormReName();

            // オーナーウィンドウの真ん中に表示
            f.StartPosition = FormStartPosition.CenterParent;
            // オーナーウィンドウにthisを指定する
            f.ShowDialog(this);
            //フォームが必要なくなったところで、Disposeを呼び出す
            f.Dispose();

            /*
             * この間、リネームダイアログでの操作
             */

            // 付箋インスタンスに新しい名前を与えてListBoxに反映させる
            FusenData fdata = (FusenData)listBox1.Items[lbSelId];

            fdata.fname             = lbSelName;
            listBox1.Items[lbSelId] = fdata;

            // ListBoxの選択Indexが変化した時のイベントをここでONにする
            listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
        }
コード例 #2
0
        // 関数:ListBoxのアイテムを新規追加
        private void ListAdd()
        {
            // ListBoxのアイテム数を調べる( = 新規追加するindex)
            int i = listBox1.Items.Count;

            // n.txtファイルを作成する
            var sw = new StreamWriter(
                TEXTFLD + @"/" + i.ToString() + @".txt",
                false,
                ENCODE);

            sw.Close();

            // ListBoxの選択アイテムの名前を取得
            lbSelName = NEWTITLE;

            // リネームダイアログを開く
            FormReName f = new FormReName();

            // オーナーウィンドウの真ん中に表示
            f.StartPosition = FormStartPosition.CenterParent;
            // オーナーウィンドウにthisを指定する
            f.ShowDialog(this);
            //フォームが必要なくなったところで、Disposeを呼び出す
            f.Dispose();

            /*
             * この間、リネームダイアログでの操作
             */

            // ダイアログで"OK"したかを判定
            if (addDo == true)
            {
                // 付箋オブジェクトを指定した名前で生成
                FusenData fdata = new FusenData(
                    lbSelName,
                    null);
                listBox1.Items.Add(fdata);
            }
        }