C# 对话框使用整理

1.保存文件对话框 

    SaveFileDialog saveFile = new SaveFileDialog();
                saveFile.Title = "save file";
                saveFile.AddExtension = true;
                saveFile.Filter = "file(*.cfg)|*.cfg|all file(*.*)|*.*";
                saveFile.InitialDirectory = runPath;
                saveFile.FileName = "default.cfg";
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    SaveDeviceDatas(saveFile.FileName);
                    MessageBox.Show("保存成功!" + saveFile.FileName, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }


2.加载文件对话框

 

 OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "cfg files(*.cfg)|*.cfg|All files|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            openFileDialog.InitialDirectory = runPath;
            openFileDialog.FileName = "default.cfg";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {               
                LoadDeviceDataFromXML(openFileDialog.FileName);

            }

 

posted @ 2018-05-08 14:54  ike_li  阅读(825)  评论(0编辑  收藏  举报