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


C# OpenFileDialog.ToString方法代碼示例

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


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

示例1: OpenFileDialogTest

		public void OpenFileDialogTest ()
		{
			ofd = new OpenFileDialog ();
			
			Assert.IsTrue (ofd.AddExtension, "#11");
			Assert.IsTrue (ofd.CheckFileExists, "#12");
			Assert.IsTrue (ofd.CheckPathExists, "#13");
			Assert.AreEqual ("", ofd.DefaultExt, "#14");
			Assert.IsTrue (ofd.DereferenceLinks, "#15");
			Assert.AreEqual ("", ofd.FileName, "#16");
			Assert.IsNotNull (ofd.FileNames, "#17");
			Assert.AreEqual (0, ofd.FileNames.Length, "#17a");
			Assert.AreEqual ("", ofd.Filter, "#18");
			Assert.AreEqual (1, ofd.FilterIndex, "#19");
			Assert.AreEqual ("", ofd.InitialDirectory, "#20");
			Assert.IsFalse (ofd.Multiselect, "#21");
			Assert.IsFalse (ofd.ReadOnlyChecked, "#22");
			Assert.IsFalse (ofd.RestoreDirectory, "#23");
			Assert.IsFalse (ofd.ShowHelp, "#24");
			Assert.IsFalse (ofd.ShowReadOnly, "#25");
			Assert.AreEqual ("", ofd.Title, "#26");
			Assert.IsTrue (ofd.ValidateNames, "#27");
			Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: , FileName: ", ofd.ToString (), "#28");
			
			ofd.DefaultExt = ".TXT";
			Assert.AreEqual ("TXT", ofd.DefaultExt, "#29");
			
			ofd.Filter = null;
			Assert.AreEqual ("", ofd.Filter, "#30");
			
			ofd.Filter = "Text (*.txt)|*.txt|All (*.*)|*.*";
			
			try {
				ofd.Filter = "abcd";
			} catch (Exception) {
			}
			
			Assert.AreEqual ("Text (*.txt)|*.txt|All (*.*)|*.*", ofd.Filter, "#30a");
			
			ofd.FilterIndex = 10;
			Assert.AreEqual (10, ofd.FilterIndex, "#30aa");
			
			ofd.Filter = null;
			Assert.AreEqual ("", ofd.Filter, "#30b");
			Assert.AreEqual (10, ofd.FilterIndex, "#30ba");
			
			string current_path = Environment.CurrentDirectory;
			string current_file = Path.Combine(current_path, "test_file");
			if (!File.Exists (current_file))
				File.Create (current_file);
			
			ofd.FileName = current_file;
			
			Assert.AreEqual (current_file, ofd.FileName, "#31");
			
			string[] file_names = ofd.FileNames;
			Assert.AreEqual (current_file, file_names [0], "#32");
			
			ofd.Title = "Test";
			Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: Test, FileName: " + current_file, ofd.ToString (), "#33");
			
			ofd.FileName = null;
			Assert.AreEqual ("", ofd.FileName, "#33a");
			Assert.IsNotNull (ofd.FileNames, "#33b");
			Assert.AreEqual (0, ofd.FileNames.Length, "#33c");
			
			ofd.Reset ();
			
			// check again
			Assert.IsTrue (ofd.AddExtension, "#34");
			Assert.IsTrue (ofd.CheckFileExists, "#35");
			Assert.IsTrue (ofd.CheckPathExists, "#36");
			Assert.AreEqual ("", ofd.DefaultExt, "#37");
			Assert.IsTrue (ofd.DereferenceLinks, "#38");
			Assert.AreEqual ("", ofd.FileName, "#39");
			Assert.IsNotNull (ofd.FileNames, "#40");
			Assert.AreEqual ("", ofd.Filter, "#41");
			Assert.AreEqual (1, ofd.FilterIndex, "#42");
			Assert.AreEqual ("", ofd.InitialDirectory, "#43");
			Assert.IsFalse (ofd.Multiselect, "#44");
			Assert.IsFalse (ofd.ReadOnlyChecked, "#45");
			Assert.IsFalse (ofd.RestoreDirectory, "#46");
			Assert.IsFalse (ofd.ShowHelp, "#47");
			Assert.IsFalse (ofd.ShowReadOnly, "#48");
			Assert.AreEqual ("", ofd.Title, "#49");
			Assert.IsTrue (ofd.ValidateNames, "#50");
			Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: , FileName: ", ofd.ToString (), "#60");
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:88,代碼來源:CommonDialogsTest.cs


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