本文整理汇总了C#中System.Windows.Forms.Form.GetAllControls方法的典型用法代码示例。如果您正苦于以下问题:C# Form.GetAllControls方法的具体用法?C# Form.GetAllControls怎么用?C# Form.GetAllControls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.GetAllControls方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitLanguage
private static void InitLanguage( Form formMain, frmDebug formDebug )
{
InterfaceLanguage engl = null;
foreach( InterfaceLanguage lang in InterfaceLanguage.Languages )
{
if( lang.Id == "engl" )
{
engl = lang;
break;
}
}
if( engl == null )
return;
List<Control> controls = new List<Control>();
formMain.GetAllControls( ref controls );
List<string> tags = new List<string>();
foreach( Control control in controls )
{
if( control.Tag != null && control.Tag.ToString().StartsWith( "lang" ) )
{
string tag = control.Tag.ToString().Substring( 4 );
if( !tags.Contains( tag ) )
tags.Add( tag );
}
}
List<string> unusedTags = tags;
TreeNode loaded = new TreeNode( "Loaded" );
foreach( InterfaceLanguage lang in InterfaceLanguage.Languages )
{
TreeNode langNode = new TreeNode( lang.Id + " (" + lang.Name + ")" );
TreeNode fields = langNode.Nodes.Add( "Fields" );
TreeNode missing = new TreeNode( "Missing" );
FieldInfo[] fieldInfos = lang.GetType().GetFields();
int fieldsCount = 0, missingCount = 0;
foreach( FieldInfo field in fieldInfos )
{
if( field.FieldType != typeof( string ) )
continue;
if( lang.Id == "engl" )
tags.Remove( field.Name );
if( field.IsInitOnly ) // readonly
continue;
fieldsCount++;
string englValue = (string)engl.GetType().GetField( field.Name ).GetValue( engl );
string value = (string)field.GetValue( lang );
fields.Nodes.Add( field.Name + " = " + value );
if( lang.Id != "engl" && value == englValue )
{
missingCount++;
missing.Nodes.Add( field.Name );
}
}
if( missing.Nodes.Count > 0 )
{
missing.Text += " (" + missingCount + "/" + fieldsCount + ")";
langNode.Nodes.Add( missing );
}
loaded.Nodes.Add( langNode );
}
if( tags.Count > 0 )
{
TreeNode notImplemented = formDebug.treeLang.Nodes.Add( "Not implemented (" + tags.Count + ")" );
foreach( string tag in tags )
{
notImplemented.Nodes.Add( tag );
}
}
if( loaded.Nodes.Count > 0 )
{
loaded.Text += " (" + loaded.Nodes.Count + ")";
formDebug.treeLang.Nodes.Add( loaded );
}
if( formDebug.treeLang.Nodes.Count == 1 )
{
formDebug.treeLang.Nodes[0].Expand();
}
}
示例2: CheckFormInputEmpty
private bool CheckFormInputEmpty(Form form)
{
//检查窗体文本为空情况
bool hasEmtpy = false;
var controls = form.GetAllControls().OfType<IControlEmptable>();
foreach (var control in controls)
{
if (!control.CanbeEmpty && string.IsNullOrEmpty(control.Text))
{
dynamic c = control as Control;
try
{
c.PromptText = control.EmptyWarning;
}
catch
{
}
control.UseWarnStyle = true;
hasEmtpy = true;
}
}
return hasEmtpy;
}