本文整理匯總了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;
}