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


C# Forms.OpenFileDialog類代碼示例

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


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

示例1: btnNew_Click

        private void btnNew_Click(object sender, EventArgs e)
        {
            // 獲取文件夾絕對路徑    顯示在 txtbox 控件裏

            System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();

            string StrFileName = "";
            // 獲取文件和路徑名 一起顯示在 txtbox 控件裏

            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string SavePathFile = AppDomain.CurrentDomain.BaseDirectory + "\\image\\gdc" +DateTime.Now.ToString("yyyyMMddHHmmss")+ ".jpg";
                StrFileName = dialog.SafeFileName;
                if (File.Exists(SavePathFile))
                {
                    File.Delete(SavePathFile);
                } File.Copy( dialog.FileName,SavePathFile);
                if (!db.InsertH_Para("H_gdc", "gdc" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", db.GetMaxID("gdc", "H_gdc")))
                {
                    MessageBox.Show("保存失敗!"); return;
                }
                else
                {
                    MessageBox.Show("保存成功!");
                    ShowDt(PageInt);
                }
            }
        }
開發者ID:SpiderLoveFish,項目名稱:HZLApp,代碼行數:29,代碼來源:gdc.cs

示例2: button3_Click

 private void button3_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count != 1)
         return;
     OpenFileDialog od = new OpenFileDialog();
     od.Filter = "Bitmap file (*.bmp)|*.bmp";
     od.FilterIndex = 0;
     if (od.ShowDialog() == DialogResult.OK)
     {
         Section s = listView1.SelectedItems[0].Tag as Section;
         try
         {
             Bitmap bmp = new Bitmap(od.FileName);
             s.import(bmp);
             bmp.Dispose();
             pictureBox1.Image = s.image();
             listView1.SelectedItems[0].SubItems[3].Text = s.cnt.ToString();
             button4.Enabled = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
開發者ID:winterheart,項目名稱:game-utilities,代碼行數:25,代碼來源:Form1.cs

示例3: OpenFile

 /// <summary>
 /// Open a new file. Will ask for the file name in a dialog.
 /// </summary>
 public void OpenFile()
 {
     OpenFileDialog dlg = new OpenFileDialog ();
     if (dlg.ShowDialog () == DialogResult.OK)
         OpenFile (dlg.FileName);
     dlg.Dispose ();
 }
開發者ID:NALSS,項目名稱:Telegraph,代碼行數:10,代碼來源:TextEditor.cs

示例4: OnClickSelect

        private void OnClickSelect(object sender, EventArgs e)
        {
            DicomFile file1 = null;
            while (true)
            {
                var ofd = new OpenFileDialog();
                ofd.Title = "Choose first DICOM file";
                ofd.Filter = "DICOM Files (*.dcm;*.dic)|*.dcm;*.dic|All Files (*.*)|*.*";

                if (ofd.ShowDialog(this) == DialogResult.Cancel) return;

                try
                {
                    file1 = DicomFile.Open(ofd.FileName);
                    break;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        this,
                        ex.Message,
                        "Error opening DICOM file",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }

            DicomFile file2 = null;
            while (true)
            {
                var ofd = new OpenFileDialog();
                ofd.Title = "Choose second DICOM file";
                ofd.Filter = "DICOM Files (*.dcm;*.dic)|*.dcm;*.dic|All Files (*.*)|*.*";

                if (ofd.ShowDialog(this) == DialogResult.Cancel) return;

                try
                {
                    file2 = DicomFile.Open(ofd.FileName);
                    break;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        this,
                        ex.Message,
                        "Error opening DICOM file",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }

            _file1 = file1;
            _file2 = file2;

            lblFile1.Text = _file1.File.Name;
            lblFile2.Text = _file2.File.Name;

            CompareFiles();
        }
開發者ID:gustavosaita,項目名稱:fo-dicom,代碼行數:60,代碼來源:MainForm.cs

示例5: OpenToolStripMenuItemClick

        private void OpenToolStripMenuItemClick(object sender, EventArgs e)
        {
            var dataPlanOpenFileDialog = new OpenFileDialog
                                             {
                                                 Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*",
                                                 FilterIndex = 1,
                                                 Multiselect = false,
                                                 RestoreDirectory = true
                                             };

            if (dataPlanOpenFileDialog.ShowDialog() != DialogResult.OK)
                return;

            try
            {
                if (File.Exists(dataPlanOpenFileDialog.FileName))
                {
                    _file = dataPlanOpenFileDialog.FileName;
                    Text = _file;
                    LoadDataPlan(DataPlan.Load(dataPlanOpenFileDialog.FileName));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
            }
        }
開發者ID:geniuslinda,項目名稱:nDump,代碼行數:27,代碼來源:MainForm.cs

示例6: AttachMenuStripEventHandlers

        /// <summary>
        /// Attaches event handlers related to 
        /// </summary>
        private void AttachMenuStripEventHandlers()
        {
            // File
            tsmNewProject.Click += (@s, e) => NewProject();
            tsmOpenProject.Click += (@s, e) => LoadProject();

            // Edit

            // View
            tsmShowStartPage.Click += (@s, e) => StartPage.Instance.Show(dockPanel);
            tsmShowProjectExplorer.Click += (@s, e) => ResourceExplorer.Instance.Show(dockPanel);

            // Project
            tsmImportResource.Click += (@s, e) =>
                {
                    var dialog = new OpenFileDialog();
                    dialog.Filter = "Image File (*.jpg;*.png)|*.jpg;*.png|Animated Image File (*.gif)|*.gif|Animat Resource (*.amt)|*.amt|BarloX Animation (*.bxa;*.ibxa)|*.bxa;*.ibxa";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        AnimatProject.Instance.ImportResource(dialog.FileName);
                    }
                };

            // Help
            tsmAbout.Click += (@s, e) =>
                    AboutWindow.Instance.Show(dockPanel, DockState.Document);
        }
開發者ID:r1cebank,項目名稱:AmiMat,代碼行數:30,代碼來源:MainForm.Events.cs

示例7: LoadNewPlugin

        public static void LoadNewPlugin(IAutoWikiBrowser awb)
        {
            OpenFileDialog pluginOpen = new OpenFileDialog();
            if (string.IsNullOrEmpty(LastPluginLoadedLocation))
                LoadLastPluginLoadedLocation();

            pluginOpen.InitialDirectory = string.IsNullOrEmpty(LastPluginLoadedLocation) ? Application.StartupPath : LastPluginLoadedLocation;
            
            pluginOpen.DefaultExt = "dll";
            pluginOpen.Filter = "DLL files|*.dll";
            pluginOpen.CheckFileExists = pluginOpen.Multiselect = /*pluginOpen.AutoUpgradeEnabled =*/ true;

            pluginOpen.ShowDialog();
            
            if (!string.IsNullOrEmpty(pluginOpen.FileName))
            {
                string newPath = Path.GetDirectoryName(pluginOpen.FileName);
                if (LastPluginLoadedLocation != newPath)
                {
                    LastPluginLoadedLocation = newPath;
                    SaveLastPluginLoadedLocation();
                }
            }

            Plugin.LoadPlugins(awb, pluginOpen.FileNames, true);
        }
開發者ID:svn2github,項目名稱:autowikibrowser,代碼行數:26,代碼來源:PluginManager.cs

示例8: OpenDialog

 public void OpenDialog(bool multipleFiles, params FileTypes[] fileTypes)
 {
     ofd = new OpenFileDialog();
     ofd.Multiselect = multipleFiles;
     ofd.Filter = Utils.FileTypesToWinFormFilter(fileTypes);
     result = ofd.ShowDialog();
 }
開發者ID:JacquesLucke,項目名稱:Collage,代碼行數:7,代碼來源:OpenFileWindow.cs

示例9: openToolStripMenuItem_Click

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = false;
            dialog.Filter = "All Supported Files |*.csv;*.txt;*.xls;*.xlsx;*.docx;*.rtf;*.eml;*.xml;*.html;*.htm;*.doc;*.ppt;*.pptx;*.cnm;*.vsd;*.pdf;*.vcf;*.zip;*.mp3;*.ape;*.wma;*.flac;*.aif;*.jpeg;*.jpg;*.tiff;*.png;*.gif";
            dialog.Filter += "|Comma Seperated Files (*.csv)|*.csv";
            dialog.Filter += "|Audio Files|*.mp3;*.ape;*.wma;*.flac;*.aif";
            dialog.Filter += "|Image Files|*.jpeg;*.jpg;*.tiff;*.png;*.gif";
            dialog.Filter += "|Zip Package|*.zip";
            dialog.Filter += "|Text Files (*.txt)|*.txt";
            dialog.Filter += "|Excel Documents|*.xls;*.xlsx";
            dialog.Filter += "|Rich Text Files (*.rtf)|*.rtf";
            dialog.Filter += "|Word Documents|*.docx;*.doc";
            dialog.Filter += "|PowerPoint Documents|*.ppt;*.pptx";
            dialog.Filter += "|Business Card Files (*.vcf)|*.vcf";
            dialog.Filter += "|Email Files (*.eml)|*.eml";
            dialog.Filter += "|Html Files (*.html, *.htm)|*.html;*.htm";
            dialog.Filter += "|XML Files (*.xml)|*.xml";
            dialog.Filter += "|Adobe PDF Files (*.pdf)|*.pdf";
            dialog.Filter += "|Pegsus Mailbox file (*.cnm)|*.cnm";

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                filepath = dialog.FileName;
            }

            OpenFile(filepath, comboBox1.Text);
        }
開發者ID:iraychen,項目名稱:toxy,代碼行數:28,代碼來源:Form1.cs

示例10: InitializeDialog

        protected override void InitializeDialog(OpenFileDialog openFileDialog)
        {
            base.InitializeDialog(openFileDialog);

            openFileDialog.CheckFileExists = false;
            openFileDialog.Filter = "Microsoft Office Access (*.mdb)|*.mdb";
        }
開發者ID:drme,項目名稱:disks-db,代碼行數:7,代碼來源:DbFileNameEditor.cs

示例11: loadButton_Click

        private void loadButton_Click(object sender, EventArgs e)
        {
            string toneSavePath;
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = CurrentOFDFilter;
                if (ofd.ShowDialog() != DialogResult.OK) return;
                toneSavePath = ofd.FileName;
            }

            try
            {
                switch (CurrentGameVersion)
                {
                    case GameVersion.RS2012:
                        toneControl1.Tone = Tone.LoadFromXmlTemplateFile(toneSavePath);
                        break;
                    case GameVersion.RS2014:
                        toneControl1.Tone = Tone2014.LoadFromXmlTemplateFile(toneSavePath);
                        break;
                }

            }
            catch (Exception ex)
            {
                toneControl1.Tone = null;
                MessageBox.Show("Can't load saved tone. \n" + ex.Message, DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("Tone was loaded.", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
開發者ID:ray,項目名稱:rocksmith-custom-song-toolkit,代碼行數:32,代碼來源:ToneForm.cs

示例12: Setup

 private void Setup()
 {
     var configSetup = new NHibernateConfigSetup();
     if (!configSetup.VerifyNHConfigFileExist())
     {
         if (MessageBox.Show("El archivo de conexión a la base de datos no existe\n" +
                             "para poder hacer uso del sistema por favor importe el archivo.\n\n",
                             "Inventarios",
                             MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
         {
             var ofdBuscarArchivo = new OpenFileDialog
                                        {
                                            InitialDirectory = "c:\\",
                                            Filter = "Data files (*.config)|*.config",
                                            FilterIndex = 2,
                                            RestoreDirectory = false
                                        };
             if (ofdBuscarArchivo.ShowDialog() == DialogResult.OK)
             {
                 File.Copy(ofdBuscarArchivo.FileName, "C:\\NHibernateSettings\\" + ofdBuscarArchivo.SafeFileName);
             }
             if (ofdBuscarArchivo.ShowDialog() == DialogResult.Cancel)
             {
                 Application.Exit();
             }
         }
         else
             Application.Exit();
     }
     else
     {
         configSetup.InitializeNHibernate();
         AutoMapperConfiguration.Configure();
     }
 }
開發者ID:giovanirguz,項目名稱:SistemaInventarios,代碼行數:35,代碼來源:FrmMainForm.cs

示例13: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string filePath = ofd.FileName;
                ArcGISTileSource suyTile = new ArcGISTileSource(filePath);
                TileLayer suyTileLyr = new TileLayer(suyTile, "suy");
                //ArcGISTileCompactSource suyTile = new ArcGISTileCompactSource(filePath);
                //ArcGISTileCompactLayer suyTileLyr = new ArcGISTileCompactLayer(suyTile, "suy");
                this.mapImage1.Map.Layers.Add(suyTileLyr);
                this.mapImage1.Map.ZoomToExtents();
                this.mapImage1.Refresh();
                //SharpMap.Data.Providers.SpatiaLite sb = new SharpMap.Data.Providers.SpatiaLite("Data Source=" + ofd.FileName, "water", "Geometry", "PK_UID");
                //VectorLayer vecLyr = new VectorLayer("sqlSpatial");
                //vecLyr.DataSource = sb;
                //this.mapImage1.Map.Layers.Add(vecLyr);
                //this.mapImage1.Map.ZoomToExtents();
                //this.mapImage1.Refresh();

            }
            //BruTile.ITileProvider tileProvider =
            ////BruTile.TileSource ts = new BruTile.TileSource(
            //this.mapImage1.Map.Layers.Add();
        }
開發者ID:F-Sidney,項目名稱:SharpMapTileLayer,代碼行數:25,代碼來源:Form1.cs

示例14: buttonChose_Click

 private void buttonChose_Click(object sender, EventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog();
     ofd.ShowDialog();
     textBoxFilePath.Text = ofd.FileName;
     filePath = textBoxFilePath.Text.Trim();
 }
開發者ID:smilelhh,項目名稱:TM,代碼行數:7,代碼來源:InData.cs

示例15: OUVRIR_Click

        private void OUVRIR_Click(object sender, EventArgs e)
        {// permet d'aller chercher dans nos dossier l'image souhaité
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg";
            //format prit en compte
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;
        

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                
                m_Bitmap = (Bitmap)Bitmap.FromFile(openFileDialog.FileName, false);
                b_Bitmap = (Bitmap)new Bitmap(m_Bitmap);
                this.AutoScroll = true;
                this.AutoScrollMinSize = new Size((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
                
                byte[] pixel_map = this.GetPixelMap(m_Bitmap);
                this.pictureBox2.Image = this.CreatationHistogram(pixel_map);
                // appel la fonction qui permet l'affichage de l'histogramme
                this.comboBox1.Enabled = true;
                this.Invalidate();
                this.Refresh();
            }


        }
開發者ID:jeremyBallot,項目名稱:projet_image_Csharp,代碼行數:29,代碼來源:Form1.cs


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