0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

名前を付けて保存

Last updated at Posted at 2024-06-17

プロジェクト開く時にpjNameを保持

    private void button5_Click_1(object sender, EventArgs e)
    {

        if (listBox1.SelectedItem == null)
        {
            MessageBox.Show("リストから選択してください");
            return;
        }
        string dir = listBox1.SelectedItem.ToString();
        pjName = dir;
        string openpath = pathProject + dir;
        open_project(openpath);
        marking();
        button4.BackColor = Color.White;

名前を付けて保存時の処理

    private void 名前を付けて保存ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        //プロジェクトを開いてなければ、処理終了
        if (path == null)
        {
            MessageBox.Show("プロジェクトを開いて下さい");
            return;
        }

        makeNewFolder3(pjName);

    }

名前を付けて保存のメソッド

    public bool makeNewFolder3(string pjName)                                                            //プロジェクト用フォルダの作成
    {
        using (Form4 form4 = new Form4(this))
        {
            form4.StartPosition = FormStartPosition.CenterParent;
            form4.textBox1.Text = pjName + "コピー";
            form4.ShowDialog();
        }

        string oldpath = pathProject + pjName;
        pjName = pjnameLabel.Text;

        if (pjName == "")
        {
            MessageBox.Show("入力して下さい");
            return (false);
        }

        if (pjName == "キャンセルボタンが押されました")
        {
            return (false);
        }


        // 新規フォルダの絶対パス
        path = pathProject + pjName;
        toolStripStatusLabel1.Text = "ファイル保存先:" + path;

        if (pjName == "")
            return (false);

        if (Directory.Exists(path))
        {
            DialogResult result = MessageBox.Show("同名のプロジェクトがあります。上書きしますか?", "上書き確認", MessageBoxButtons.YesNo);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {

                Directory.Delete(path, true);        //第2引数をtrueにすることで、フォルダの中身を含めて全削除。
                Directory.CreateDirectory(path);
                return (true);

            }
            else if (result == System.Windows.Forms.DialogResult.No)
            {
                return (false);
            }
        }

        Directory.CreateDirectory(path);
        var files = Directory.GetFiles(oldpath, "*", SearchOption.TopDirectoryOnly);
        foreach ( var file in files)
        {
            File.Copy(oldpath + "\\" + Path.GetFileName(file), path + "\\" + Path.GetFileName(file));
        }


        return (true);
    }

プロジェクト開く時の個人設定読み込み

    public void open_project(string openpath)
    {
        clear();

        //パブリックpathを更新しておく(他の関数で影響あるため)
        path = openpath;

        //画像を開く
        open_bitmap();

        //dataGridView1にLict.csvを読み込む
        string pathGrid1 = openpath + "\\List.csv";
        openpath = pathGrid1;
        Control[] cs = this.Controls.Find("dataGridView1", true);
        bool flag = open_grid(openpath, cs, false);

        //読み込みに失敗した場合、
        if (flag == false)
        {
            toolStripStatusLabel1.Text = "保存先:" + path;
            return;
        }

        for (int i = 3; i <= 15; i++)
        {
            string openpath2 = path + "\\dataGridView" + i + ".csv";

            if (File.Exists(openpath2))
            {
                Control[] cs2 = this.Controls.Find("dataGridView" + i.ToString(), true);
                open_grid(openpath2, cs2, false);
            }

        }

        tabControl1.SelectedIndex = 1;
        toolStripStatusLabel1.Text = "保存先:" + path;
        button4.BackColor = Color.White;
    }   
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?