當前位置: 首頁>>代碼示例>>C#>>正文


C# OpenFileDialog.SetPlaces方法代碼示例

本文整理匯總了C#中System.Windows.Forms.OpenFileDialog.SetPlaces方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenFileDialog.SetPlaces方法的具體用法?C# OpenFileDialog.SetPlaces怎麽用?C# OpenFileDialog.SetPlaces使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.OpenFileDialog的用法示例。


在下文中一共展示了OpenFileDialog.SetPlaces方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (sender.Equals(_btnSelect))
            {
                using (MyOpenFileDialogControl openDialog = new MyOpenFileDialogControl())
                {
                    if (openDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        lblFilePath.Text = openDialog.MSDialog.FileName;
                    }
                }

            }
            else if (sender.Equals(_btnSave))
            {
                using (MySaveDialogControl saveDialog = new MySaveDialogControl(lblFilePath.Text, this))
                {
                    if (saveDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        lblFilePath.Text = saveDialog.MSDialog.FileName;
                    }
                }
            }
            else if (sender.Equals(this._btnExtension))
            {
                using (MyOpenFileDialogControl openDialogCtrl = new MyOpenFileDialogControl())
                {
                    openDialogCtrl.FileDlgInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                    OpenFileDialog openDialog = new OpenFileDialog();
                    openDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                    openDialog.AddExtension = true;
                    openDialog.Filter = "Image Files(*.bmp)|*.bmp |Image Files(*.JPG)|*.JPG|Image Files(*.jpeg)|*.jpeg|Image Files(*.GIF)|*.GIF|Image Files(*.emf)|*emf.|Image Files(*.ico)|*.ico|Image Files(*.png)|*.png|Image Files(*.tif)|*.tif|Image Files(*.wmf)|*.wmf|Image Files(*.exif)|*.exif";
                    openDialog.FilterIndex = 2;
                    openDialog.CheckFileExists = true;
                    openDialog.DefaultExt = "jpg";
                    openDialog.FileName = "Select Picture";
                    openDialog.DereferenceLinks = true;
                    //openDialog.ShowHelp = true;
                    if (Environment.OSVersion.Version.Major < 6)
                         openDialog.SetPlaces(new object[] { @"c:\", (int)Places.MyComputer, (int)Places.Favorites, (int)Places.Printers, (int)Places.Fonts });
                    if (openDialog.ShowDialog(openDialogCtrl, this) == DialogResult.OK)
                    {
                        lblFilePath.Text = openDialog.FileName;
                    }
                }
            }
            else if (sender.Equals(_btnSaveExt))
            {
                using (SaveFileDialog saveDialog = new SaveFileDialog())
                {
                    MySaveDialogControl saveDialogCtrl = new MySaveDialogControl(lblFilePath.Text, this);
                    saveDialogCtrl.FileDlgInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                    saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                    saveDialog.AddExtension = true;
                    saveDialog.Filter = "Image Files(*.bmp)|*.bmp |Image Files(*.JPG)|*.JPG|Image Files(*.jpeg)|*.jpeg|Image Files(*.GIF)|*.GIF|Image Files(*.emf)|*emf.|Image Files(*.ico)|*.ico|Image Files(*.png)|*.png|Image Files(*.tif)|*.tif|Image Files(*.wmf)|*.wmf|Image Files(*.exif)|*.exif";
                    saveDialog.FilterIndex = 2;
                    saveDialog.CheckFileExists = true;
                    saveDialog.DefaultExt = "jpg";
                    saveDialog.FileName = "Change Picture";
                    saveDialog.DereferenceLinks = true;
                    //saveDialog.ShowHelp = true;
                    if (Environment.OSVersion.Version.Major < 6)
                        saveDialog.SetPlaces(new object[] { (int)Places.Desktop, (int)Places.Printers, (int)Places.Favorites, (int)Places.Programs, (int)Places.Fonts, });
                    if (saveDialog.ShowDialog(saveDialogCtrl, this) == DialogResult.OK)
                    {
                        lblFilePath.Text = saveDialog.FileName;
                    }
                }
            }
            else if (sender.Equals(_btnExit))
                this.Close();

            System.GC.Collect();
            GC.WaitForPendingFinalizers();
        }
開發者ID:NoxHarmonium,項目名稱:enform,代碼行數:75,代碼來源:FormMain.cs


注:本文中的System.Windows.Forms.OpenFileDialog.SetPlaces方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。