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


C# ContainerControl.ValidateChildren方法代碼示例

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


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

示例1: ValidationChildren

		public void ValidationChildren ()
		{
			string validating = string.Empty;
			string validated = string.Empty;
			
			Form f = new Form ();
			f.ShowInTaskbar = false;
			
			ContainerControl cc = new ContainerControl ();
			f.Controls.Add (cc);
			
			TextBox t = new TextBox ();
			t.Validating += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { validating += ("t;"); });
			t.Validated += new EventHandler (delegate (Object obj, EventArgs e) { validated += ("t;"); });
			cc.Controls.Add (t);

			TextBox t1 = new TextBox ();
			t1.Validating += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { validating += ("t1;"); });
			t1.Validated += new EventHandler (delegate (Object obj, EventArgs e) { validated += ("t1;"); });
			t1.TabStop = false;
			cc.Controls.Add (t1);

			TextBox t2 = new TextBox ();
			t2.Validating += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { validating += ("t2;"); });
			t2.Validated += new EventHandler (delegate (Object obj, EventArgs e) { validated += ("t2;"); });
			t2.Visible = false;
			cc.Controls.Add (t2);

			TextBox t3 = new TextBox ();
			t3.Validating += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { validating += ("t3;"); });
			t3.Validated += new EventHandler (delegate (Object obj, EventArgs e) { validated += ("t3;"); });
			t3.Enabled = false;
			cc.Controls.Add (t3);

			Panel p = new Panel ();
			cc.Controls.Add (p);
			
			TextBox t4 = new TextBox ();
			t4.Validating += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { validating += ("t4;"); });
			t4.Validated += new EventHandler (delegate (Object obj, EventArgs e) { validated += ("t4;"); });
			p.Controls.Add (t4);

			Label l = new Label ();
			l.Validating += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { validating += ("l;"); });
			l.Validated += new EventHandler (delegate (Object obj, EventArgs e) { validated += ("l;"); });
			cc.Controls.Add (l);
	
			f.Show ();
			
			cc.ValidateChildren ();
			Assert.AreEqual ("t;t1;t2;t3;t4;", validating, "A4a");
			Assert.AreEqual ("t;t1;t2;t3;t4;", validated, "A4b");
			validating = string.Empty; validated = string.Empty;

			cc.ValidateChildren (ValidationConstraints.Enabled);
			Assert.AreEqual ("t;t1;t2;t4;l;", validating, "A5a");
			Assert.AreEqual ("t;t1;t2;t4;l;", validated, "A5b");
			validating = string.Empty; validated = string.Empty;

			cc.ValidateChildren (ValidationConstraints.ImmediateChildren);
			Assert.AreEqual ("t;t1;t2;t3;l;", validating, "A6a");
			Assert.AreEqual ("t;t1;t2;t3;l;", validated, "A6b");
			validating = string.Empty; validated = string.Empty;

			cc.ValidateChildren (ValidationConstraints.None);
			Assert.AreEqual ("t;t1;t2;t3;t4;l;", validating, "A7a");
			Assert.AreEqual ("t;t1;t2;t3;t4;l;", validated, "A7b");
			validating = string.Empty; validated = string.Empty;

			cc.ValidateChildren (ValidationConstraints.Selectable);
			Assert.AreEqual ("t;t1;t2;t3;t4;", validating, "A8a");
			Assert.AreEqual ("t;t1;t2;t3;t4;", validated, "A8b");
			validating = string.Empty; validated = string.Empty;

			cc.ValidateChildren (ValidationConstraints.TabStop);
			Assert.AreEqual ("t;t2;t3;t4;", validating, "A9a");
			Assert.AreEqual ("t;t2;t3;t4;", validated, "A9b");
			validating = string.Empty; validated = string.Empty;

			cc.ValidateChildren (ValidationConstraints.Visible);
			Assert.AreEqual ("t;t1;t3;t4;l;", validating, "A10a");
			Assert.AreEqual ("t;t1;t3;t4;l;", validated, "A10b");
			validating = string.Empty; validated = string.Empty;

			cc.ValidateChildren (ValidationConstraints.Enabled | ValidationConstraints.Visible | ValidationConstraints.Selectable);
			Assert.AreEqual ("t;t1;t4;", validating, "A11a");
			Assert.AreEqual ("t;t1;t4;", validated, "A11b");
			validating = string.Empty; validated = string.Empty;
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:89,代碼來源:ContainerControlTest.cs


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