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


C# DateTimePicker.CreateControl方法代碼示例

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


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

示例1: TextTest

		public void TextTest ()
		{
			CheckCulture ();

			DateTimePicker dt = new DateTimePicker ();
			EventLogger log = new EventLogger (dt);
			DateTime tomorrow = DateTime.Today.AddDays (1);

			log.Clear ();
			dt.Value = tomorrow;
			Assert.AreEqual ("", dt.Text, "#1");
			Assert.IsTrue (log.ContainsEventsOrdered ("ValueChanged"), "#1.1");

			log.Clear ();
			dt.CreateControl ();
			Assert.AreEqual (tomorrow.ToLongDateString (), dt.Text, "#2");
			Assert.IsTrue (log.ContainsEventsOrdered ("HandleCreated"), "#2.1");

			log.Clear ();
			dt.Text = "";
			Assert.AreEqual (DateTime.Today.ToLongDateString (), dt.Text, "#3");
			Assert.IsTrue (log.ContainsEventsOrdered ("ValueChanged", "TextChanged"), "#3.1");
			
			log.Clear ();
			dt.Text = null;
			Assert.AreEqual (DateTime.Today.ToLongDateString (), dt.Text, "#4");
			Assert.IsTrue (log.ContainsEventsOrdered ("ValueChanged", "TextChanged"), "#4.1, expected ValueChanged+TextChanged, got: " + log.EventsJoined ());

			log.Clear (); 
			dt.CustomFormat = "yyyy-MM-dd HH-mm";
			dt.Format = DateTimePickerFormat.Custom;
			Assert.AreEqual (DateTime.Now.ToString (dt.CustomFormat), dt.Text, "#5");
			Assert.IsTrue (log.ContainsEventsOrdered ("HandleDestroyed", "HandleCreated", "FormatChanged"), "#5.1");

			log.Clear ();
			dt.CustomFormat = "yyyy-MM-dd";
			Assert.AreEqual (DateTime.Now.ToString (dt.CustomFormat), dt.Text, "#6");
			Assert.AreEqual ("", log.EventsJoined (), "#6.1");
			
			log.Clear ();
			dt.Format = DateTimePickerFormat.Short;
			Assert.AreEqual (DateTime.Now.ToShortDateString (), dt.Text, "#7");
			Assert.IsTrue (log.ContainsEventsOrdered ("HandleDestroyed", "HandleCreated", "FormatChanged"), "#7.1");

			dt.Value = DateTime.Today;
			log.Clear ();
			dt.Value = DateTime.Today;
			Assert.AreEqual (0, log.EventsRaised, "#8");

			dt.Text = null;
			log.Clear ();
			dt.Text = null;
			Assert.IsTrue (log.ContainsEventsOrdered ("ValueChanged", "TextChanged"), "#9, expected ValueChanged+TextChanged, got: " + log.EventsJoined ());
			
			dt.Text = "";
			log.Clear ();
			dt.Text = "";
			Assert.IsTrue (log.ContainsEventsOrdered ("ValueChanged", "TextChanged"), "#19, expected ValueChanged+TextChanged, got: " + log.EventsJoined ());
		}
開發者ID:ItsVeryWindy,項目名稱:mono,代碼行數:59,代碼來源:DateTimePickerTest.cs


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