开发者

C# Windows Forms: OpenFileDialog Strange Issues

开发者 https://www.devze.com 2023-03-20 02:03 出处:网络
This is kinda strange, let me try to explain it as best as possible: When I create a new file and Save it, it saves correctly (test.xml).

This is kinda strange, let me try to explain it as best as possible:

When I create a new file and Save it, it saves correctly (test.xml). When I make changes to this file and Save it, it saves correctly (to test.xml) When I make changes again to this file or just choose Save As, it works correctly (newtest.xml)

However, when I do a file open, make changes to a file (test.xml) and click Save it is saving to (newtest.xml).

This is in my MainForm.cs

            if (this.openEditorDialog1.ShowDialog(this) == DialogResult.OK && editForm != null)
        {


            editForm.Close();                
            editForm = new EditorForm(this);
            editForm.OpenFile(this.openEditorDialog1.FileName);
            editForm.Closing += new CancelEventHandler(EditorForm_Closing);
            editForm.MdiParent = this;
            editForm.Show();
        }

private void biFileSave_Click(object sender, EventArgs e)
{
if (!editForm.HasFileName)
            {
                if (this.saveEditorDialog1.ShowDialog(this) == DialogResult.OK)
                {
                    this.ActiveDiagram.SaveSoap(this.saveEditorDialog1.FileName);
                    editForm.FileName = this.saveEditorDialog1.FileName;
                }
            }
            el开发者_开发百科se
            {
                this.ActiveDiagram.SaveSoap(this.saveEditorDialog1.FileName);
            }

This is in my EditorForm.cs

  public void OpenFile(string strFileName)
    {

        diagramComponent.LoadSoap(mainForm.openEditorDialog1.FileName);
        this.FileName = mainForm.openEditorDialog1.FileName;
        this.tabControl1.SelectedTab = DiagramTab;

    }

I'm sure it has to do with the what I'm doing in the EditoForm but I can't seem to figure it out.


else
{
    this.ActiveDiagram.SaveSoap(this.saveEditorDialog1.FileName);

It looks like you want:

    this.ActiveDiagram.SaveSoap(editForm.FileName);


It must have to do with mainForm.openEditorDialog1.FileName. Use a FileName property of the form that does the saving. When you open the file, set the fileName to mainForm.openEditorDialog1.FileName. When you SaveAs, set the FileName property there, too. This way, whenever the current file, changes you set the FileName property appropriately. Then, when it comes time to save the file, you always have the correct filename.

In summary, only use the .FileName property of the SaveAs dialog or the FileOpen dialog right after you use them.

0

精彩评论

暂无评论...
验证码 换一张
取 消