当前位置: 首页>>代码示例>>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;未经允许,请勿转载。