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


C# OpenFileDialog.ShowDialog方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: button4_Click

        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDia = new OpenFileDialog();
            fileDia.Title = "Please select the data.dat file to extract.";
            fileDia.Filter = "data.dat|*.dat";
            fileDia.DefaultExt = "*.dat";
            fileDia.ShowDialog();

            string dataPath = fileDia.FileName;

            fileDia.Title = "Please select the resource.dat file to extract.";
            fileDia.Filter = "resource.dat|*.dat";
            fileDia.ShowDialog();

            string resourcesPath = fileDia.FileName;

            string targetPath = Application.StartupPath;
            //System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "ftldat unpack \"" + dataPath + "\" \"" + targetPath + "\"\\data\\");

            System.Diagnostics.Process.Start("cmd", "/c " + "ftldat unpack \"" + dataPath + "\" \"" + targetPath + "\\data\"");
            System.Diagnostics.Process.Start("cmd", "/c " + "ftldat unpack \"" + resourcesPath + "\" \"" + targetPath + "\\resource\"");
            tbPathData.Text = targetPath + "\\data\\";
            dataPath = targetPath + "\\data\\";
            tbPathResources.Text = targetPath + "\\resource\\";
            resPath = targetPath + "\\resource\\";
            UpdatePaths();
            fileDia.Dispose();
        }
開發者ID:nyteshade,項目名稱:FTLEdit,代碼行數:28,代碼來源:OptionsForm.cs

示例4: OnClick

    public void OnClick()
    {
        if (Application.platform == RuntimePlatform.WindowsPlayer ||
            Application.platform == RuntimePlatform.WindowsEditor)
        {
            System.Windows.Forms.OpenFileDialog opDialog = new System.Windows.Forms.OpenFileDialog();
            opDialog.DefaultExt = "*.ogg";
            opDialog.Filter = "Audio 파일(*.ogg) |*.ogg|모든 파일(*.*)|*.*";

            if (opDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (opDialog.CheckFileExists)
                {
                    if (_mainAudioSource != null)
                    {
                        AudioLoad(opDialog.FileName);
                    }
                    else if (Debug.isDebugBuild)
                    {
                        Debug.LogError("Main Audio Source is NULL!");
                    }
                }
                else if (Debug.isDebugBuild)
                {
                    Debug.LogError("Audio File was not Exists!");
                }
            }

            opDialog.Reset();
            opDialog.DefaultExt = "*.txt";
            opDialog.Filter = "Script Txt 파일(*.txt) |*.txt|모든 파일(*.*)|*.*";

            // Load Script
            if (opDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (opDialog.CheckFileExists)
                {
                    if (MkManager.Instance != null)
                    {
                        MkManager.Instance.AnimeScriptParse(opDialog.FileName);
                    }
                    else if (Debug.isDebugBuild)
                    {
                        Debug.LogError("MkParser was not Exists!");
                    }
                }
                else if (Debug.isDebugBuild)
                {
                    Debug.LogError("Script File was not Exists!");
                }

                _isLoaded = true;
            }

            if (_mainAudioSource != null)
            {
                _mainAudioSource.Play();
            }
        }
    }
開發者ID:TeamCafe,項目名稱:MilkSimpleAnimationScript,代碼行數:60,代碼來源:PlayerLoader.cs

示例5: btnOpenXml_Click

        private void btnOpenXml_Click(object sender, EventArgs e)
        {
            LoadXML xml = new LoadXML();
            string pfad = null;
            //Öffnet OpenFileDialog
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            DialogResult result = openFileDialog1.ShowDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog1.OpenFile() != null)
                {
                    //Öffnet Explorer und ermittelt den Eingegebenen Dateipfad
                    string file = openFileDialog1.FileName;
                    try
                    {
                        pfad = openFileDialog1.FileName;
                    }
                    //TODO: Ausnahme hinzufügen
                    catch (IOException)
                    {

                    }
                }
                //Dateipfad wird an die Klasse ladeXML übergeben
                Console.WriteLine(result);
                Console.WriteLine(pfad);
                xml.ladeXML(pfad);

            }
        }
開發者ID:vikinger,項目名稱:ibsys2tool,代碼行數:35,代碼來源:UserControl_Prognose.cs

示例6: Main

        static void Main(string[] args)
        {
            //Excel worksheet combine example
            //You will be prompted to select two Excel files. test.xls will be created that combines the sheets
			//Note: This example does not check for duplicate sheet names. Your test files should have different sheet names.
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Excel document (*.xls)|*.xls";
            ofd.Title = "Select first Excel document";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                HSSFWorkbook book1 = new HSSFWorkbook(new FileStream(ofd.FileName, FileMode.Open));
                ofd.Title = "Select second Excel document";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    HSSFWorkbook book2 = new HSSFWorkbook(new FileStream(ofd.FileName, FileMode.Open));
                    HSSFWorkbook product = new HSSFWorkbook();

                    for (int i = 0; i < book1.NumberOfSheets; i++)
                    {
                        HSSFSheet sheet1 = book1.GetSheetAt(i) as HSSFSheet;
                        sheet1.CopyTo(product, sheet1.SheetName, true, true);
                    }
                    for (int j = 0; j < book2.NumberOfSheets; j++)
                    {
                        HSSFSheet sheet2 = book2.GetSheetAt(j) as HSSFSheet;
                        sheet2.CopyTo(product, sheet2.SheetName, true, true);
                    }
                    product.Write(new FileStream("test.xls", FileMode.Create, FileAccess.ReadWrite));
                }
                
            }
        }
開發者ID:89sos98,項目名稱:npoi,代碼行數:32,代碼來源:Program.cs

示例7: FileSelectFile

        // TODO: organise Dialogs.cs

        #region FileSelectFile

        /// <summary>
        /// Displays a standard dialog that allows the user to open or save files.
        /// </summary>
        /// <param name="OutputVar">The user selected files.</param>
        /// <param name="Options">
        /// <list type="bullet">
        /// <item><term>M</term>: <description>allow muliple files to be selected.</description></item>
        /// <item><term>S</term>: <description>show a save as dialog rather than a file open dialog.</description></item>
        /// <item><term>1</term>: <description>only allow existing file or directory paths.</description></item>
        /// <item><term>8</term>: <description>prompt to create files.</description></item>
        /// <item><term>16:</term>: <description>prompt to overwrite files.</description></item>
        /// <item><term>32</term>: <description>follow the target of a shortcut rather than using the shortcut file itself.</description></item>
        /// </list>
        /// </param>
        /// <param name="RootDir">The file path to initially select.</param>
        /// <param name="Prompt">Text displayed in the window to instruct the user what to do.</param>
        /// <param name="Filter">Indicates which types of files are shown by the dialog, e.g. <c>Audio (*.wav; *.mp2; *.mp3)</c>.</param>
        public static void FileSelectFile(out string OutputVar, string Options, string RootDir, string Prompt, string Filter)
        {
            bool save = false, multi = false, check = false, create = false, overwite = false, shortcuts = false;

            Options = Options.ToUpperInvariant();

            if (Options.Contains("M"))
            {
                Options = Options.Replace("M", string.Empty);
                multi = true;
            }

            if (Options.Contains("S"))
            {
                Options = Options.Replace("S", string.Empty);
                save = true;
            }

            int result;

            if (int.TryParse(Options.Trim(), out result))
            {
                if ((result & 1) == 1 || (result & 2) == 2)
                    check = true;

                if ((result & 8) == 8)
                    create = true;

                if ((result & 16) == 16)
                    overwite = true;

                if ((result & 32) == 32)
                    shortcuts = true;
            }

            ErrorLevel = 0;
            OutputVar = null;

            if (save)
            {
                var saveas = new SaveFileDialog { CheckPathExists = check, CreatePrompt = create, OverwritePrompt = overwite, DereferenceLinks = shortcuts, Filter = Filter };
                var selected = dialogOwner == null ? saveas.ShowDialog() : saveas.ShowDialog(dialogOwner);

                if (selected == DialogResult.OK)
                    OutputVar = saveas.FileName;
                else
                    ErrorLevel = 1;
            }
            else
            {
                var open = new OpenFileDialog { Multiselect = multi, CheckFileExists = check, DereferenceLinks = shortcuts, Filter = Filter };
                var selected = dialogOwner == null ? open.ShowDialog() : open.ShowDialog(dialogOwner);

                if (selected == DialogResult.OK)
                    OutputVar = multi ? string.Join("\n", open.FileNames) : open.FileName;
                else
                    ErrorLevel = 1;
            }
        }
開發者ID:lnsoso,項目名稱:IronAHK,代碼行數:80,代碼來源:Dialogs.cs

示例8: Main

        static void Main()
        {
            var openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "Select a file from the files to assemble";
            openFileDialog.InitialDirectory = new DirectoryInfo("../../../").FullName;

            string filePath;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                filePath = openFileDialog.FileName;
            }
            else
            {
                throw new ApplicationException("No file selected");
            }

            string slicesDirectroy = new FileInfo(filePath).DirectoryName;

            List<FileInfo> files = Directory
                .GetFiles(slicesDirectroy)
                .OrderBy(name => name)
                .Select(file => new FileInfo(file))
                .ToList();

            openFileDialog.Title = "Select a directroy to save the assembled file";

            string outputDirectory;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                filePath = openFileDialog.FileName;
            }
            else
            {
                throw new ApplicationException("No file selected");
            }

            Console.WriteLine("Assembling Files...");
            var sw = new Stopwatch();
            sw.Start();
            Task asyncTask = AssembleAsync(files, "../../../Assembled");

            int left = Console.CursorLeft;
            double currentSecond = sw.Elapsed.TotalSeconds;

            while (!asyncTask.IsCompleted)
            {
                if (sw.Elapsed.TotalSeconds >= currentSecond + 1)
                {
                    currentSecond = sw.Elapsed.TotalSeconds;
                    Console.Write("{0}", Math.Floor(currentSecond));
                    Console.CursorLeft = left;
                }
            }
            
            Console.WriteLine("Completed... {0}", sw.Elapsed);
        }
開發者ID:kidroca,項目名稱:Advanced-CSharp-2015,代碼行數:56,代碼來源:Program.cs

示例9: GetPathFromDialog

		public static string GetPathFromDialog()
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "Text files (*.csv)|*.csv";
			openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
			if (openFileDialog.ShowDialog() == DialogResult.OK || openFileDialog.ShowDialog() == DialogResult.Yes)
			{
				return openFileDialog.FileName;
			}
			return null;
		}
開發者ID:justdude,項目名稱:DbExport,代碼行數:11,代碼來源:CFileHelper.cs

示例10: btnBrowse_Click

 private void btnBrowse_Click(object sender, EventArgs e)
 {
     OpenFileDialog dlg = new OpenFileDialog();
     dlg.ShowDialog();
     if (dlg.ShowDialog()== DialogResult.OK )
     {
         string fileName;
         fileName = dlg.FileName;
         txtFile.Text = fileName;
         btnSend2.Enabled = true;
     }
 }
開發者ID:anggia81,項目名稱:OOP,代碼行數:12,代碼來源:ClientTest.cs

示例11: callOpenFileDialog

 private static string[] callOpenFileDialog(string startpath, string fileTypes, bool multiSelect, IWin32Window parentForm, ScriptEngine engine)
 {
     try {
         OpenFileDialog dlg = new OpenFileDialog();
         dlg.InitialDirectory = startpath;
         dlg.Filter = fileTypes;
         dlg.Multiselect = multiSelect;
         DialogResult result = parentForm == null ? dlg.ShowDialog() : dlg.ShowDialog(parentForm);
         return result == DialogResult.OK ? dlg.FileNames : new string[0];
     } catch (Exception ex) {
         throw ex.convertException(engine);
     }
 }
開發者ID:JLChnToZ,項目名稱:BlockEditorTest,代碼行數:13,代碼來源:FileIOFunctions.cs

示例12: Browse

        private void Browse(object sender, EventArgs e)
        {
            Button b = sender as Button;
            TextBox t = b.Tag as TextBox;

            OpenFileDialog ofd = new OpenFileDialog();
            SaveFileDialog sfd = new SaveFileDialog();

            if (t.Name == "txtInput")
            {
                // ofd
                ofd.Filter = "Bitmap Files (*.bmp)|*.bmp";
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
                t.Text = ofd.FileName;
            }
            else if (t.Name == "txtOutput")
            {
                if (rdbHide.Checked)
                {
                    // sfd
                    sfd.Filter = "Bitmap Files (*.bmp)|*.bmp";
                    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
                    t.Text = sfd.FileName;
                }
                else
                {
                    // ofd
                    ofd.Filter = "Bitmap Files (*.bmp)|*.bmp";
                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
                    t.Text = ofd.FileName;
                }

            }
            else if (t.Name == "txtData")
            {
                if (rdbHide.Checked)
                {
                    // ofd
                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
                    t.Text = ofd.FileName;
                }
                else
                {
                    // sfd
                    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
                    t.Text = sfd.FileName;
                }
            }
        }
開發者ID:santoshkumarsingh,項目名稱:Steganography,代碼行數:49,代碼來源:Form1.cs

示例13: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     OpenFileDialog f = new OpenFileDialog(); //création d'une fenetre d'exploration
     f.Title = "Choisir le fichier à importer";
     if (f.ShowDialog() == DialogResult.OK) //si fond est coché
     {
         f.Filter = "Images(*.ZIP)|*.ZIP"; //filtre le type de fichier autorisé
         f.ShowDialog(); //affiche la boite de dialogue
         theme = f.FileName;
     }
     else
     {
         MessageBox.Show("Erreur");
     }
 }
開發者ID:ArukaHFS,項目名稱:Ztheme,代碼行數:15,代碼來源:Form1.cs

示例14: Main

 private static void Main()
 {
     Console.WriteLine("Hello World!");
     OpenFileDialog dlgOpen = new OpenFileDialog();
     Console.WriteLine("Dumaan na dito!");
     dlgOpen.ShowDialog();
     Console.WriteLine("Ito na ulit!");
     if (dlgOpen.ShowDialog() == DialogResult.OK)
     {
       string s = dlgOpen.FileName;
       Console.WriteLine("Filename " + s);
       Console.WriteLine(" Created at " + File.GetCreationTime(s));
       Console.WriteLine(" Accessed at " + File.GetLastAccessTime(s));
     }
 }
開發者ID:ChanahC,項目名稱:CSharpTrain,代碼行數:15,代碼來源:FileTry.cs

示例15: 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


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