G gusse.net Dec 25, 2006 #1 how do I get a list of all components on a form using reflection ?? or is there another way of doing this ?? can anyone help ??
how do I get a list of all components on a form using reflection ?? or is there another way of doing this ?? can anyone help ??
C Cor Ligthert [MVP] Dec 26, 2006 #2 gusse, What are all components on a form in your idea, normally those things have the name controls and can be get easily in a recursive loop? Cor
gusse, What are all components on a form in your idea, normally those things have the name controls and can be get easily in a recursive loop? Cor
O Oliver Sturm Jan 2, 2007 #3 Hello gusse, how do I get a list of all components on a form using reflection ?? Click to expand... Assuming you are in the constructor (and I understand all kinds of missing details about your question correctly <g>): Type formType = this.GetType( ); FieldInfo[] fields = formType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic); foreach (FieldInfo field in fields) { if (typeof(Component).IsAssignableFrom(field.FieldType)) Debug.WriteLine(field.Name); } or is there another way of doing this ?? Click to expand... Is there another way of doing what? Oliver Sturm
Hello gusse, how do I get a list of all components on a form using reflection ?? Click to expand... Assuming you are in the constructor (and I understand all kinds of missing details about your question correctly <g>): Type formType = this.GetType( ); FieldInfo[] fields = formType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic); foreach (FieldInfo field in fields) { if (typeof(Component).IsAssignableFrom(field.FieldType)) Debug.WriteLine(field.Name); } or is there another way of doing this ?? Click to expand... Is there another way of doing what? Oliver Sturm