D
dantheman
Hi,
i'm doing a programe in a few languages so i've found this code that
iterates through the form controls and returns there names
so i can switch languages
but the problem is after re-parenting the controls to optimize the code
i don't get the names of the controls on my groupbox or my panels see
note in getcontrolname what can i do to make it work
this is for the .net compact framework so getchild etc is not available
any help would be apreciated
here's the code
//will do translation of form controls
private void TranslateForm()
{
string s;
foreach (Control ctrl in this.Controls)
if ((object)(s = resManager.GetString(GetControlName(ctrl),
currentCulture)) != null)
ctrl.Text = s;
}
//will get control names
private 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)
) //this line is true only if the control is on the form directly not
if the control is on the groupbox or panel
return f.Name;
return null;
}
i'm doing a programe in a few languages so i've found this code that
iterates through the form controls and returns there names
so i can switch languages
but the problem is after re-parenting the controls to optimize the code
i don't get the names of the controls on my groupbox or my panels see
note in getcontrolname what can i do to make it work
this is for the .net compact framework so getchild etc is not available
any help would be apreciated
here's the code
//will do translation of form controls
private void TranslateForm()
{
string s;
foreach (Control ctrl in this.Controls)
if ((object)(s = resManager.GetString(GetControlName(ctrl),
currentCulture)) != null)
ctrl.Text = s;
}
//will get control names
private 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)
) //this line is true only if the control is on the form directly not
if the control is on the groupbox or panel
return f.Name;
return null;
}