G
Gary Hower
I recently read an article by an MVP Chris Tacke describing the use of
reflection to get the name/ID of a CF control on a windows form.
The Article: http://blog.opennetcf.org/ctacke/PermaLink.aspx/64c28b10-d3a8-4c6b-b11a-2ae2de4bdaf1
I have also read a few articles where people are describing the use of
the code segment Chris provided. There seems to be an issue with the
code example as it relates to Control placed on panels.
Would anyone have a good solution to this problem. It seems the
methods Chris wrote do not account for panels as the parent to other
controls.
Is anyone familiar with this problem or have another solution to
determine the Name/ID of a control thru code.
example:
Chris' method:
--------------
public static string GetControlName(object SourceControl)
{
FieldInfo[] fi = ((Control)SourceControl).Parent.GetType().GetFields(BindingFlags.NonPublic
| BindingFlags.Instance |BindingFlags.Public |
BindingFlags.IgnoreCase);
foreach(FieldInfo f in fi)
{
if(f.GetValue(((Control)SourceControl).Parent).Equals(SourceControl))
return f.Name;
}
return null;
}
What would be great would be if you could use the Object sender from
an event to determine the Name/ID of the control this would allow for
more flexible and smaller code when dealing with lots of Controls.
Any help with this matter would be greatly appreciated.
I would like to Correspond with an MVP on this matter if possible.
reflection to get the name/ID of a CF control on a windows form.
The Article: http://blog.opennetcf.org/ctacke/PermaLink.aspx/64c28b10-d3a8-4c6b-b11a-2ae2de4bdaf1
I have also read a few articles where people are describing the use of
the code segment Chris provided. There seems to be an issue with the
code example as it relates to Control placed on panels.
Would anyone have a good solution to this problem. It seems the
methods Chris wrote do not account for panels as the parent to other
controls.
Is anyone familiar with this problem or have another solution to
determine the Name/ID of a control thru code.
example:
Chris' method:
--------------
public static string GetControlName(object SourceControl)
{
FieldInfo[] fi = ((Control)SourceControl).Parent.GetType().GetFields(BindingFlags.NonPublic
| BindingFlags.Instance |BindingFlags.Public |
BindingFlags.IgnoreCase);
foreach(FieldInfo f in fi)
{
if(f.GetValue(((Control)SourceControl).Parent).Equals(SourceControl))
return f.Name;
}
return null;
}
What would be great would be if you could use the Object sender from
an event to determine the Name/ID of the control this would allow for
more flexible and smaller code when dealing with lots of Controls.
Any help with this matter would be greatly appreciated.
I would like to Correspond with an MVP on this matter if possible.