コード例 #1
0
        private static void LocaliseControl <T>(T control, System.Windows.Forms.ToolTip toolTip = null)
        {
            if (control is System.Windows.Forms.Control.ControlCollection) // Window forms controls
            {
                System.Windows.Forms.Control.ControlCollection ctl = control as System.Windows.Forms.Control.ControlCollection;

                foreach (System.Windows.Forms.Control childCtl in ctl) // look for all child controls
                {
                    if (toolTip != null)
                    {
                        toolTip.SetToolTip(childCtl, Localise.GetPhrase(toolTip.GetToolTip(childCtl)));
                    }

                    if ((childCtl.GetType() == typeof(System.Windows.Forms.Label)) || (childCtl.GetType() == typeof(System.Windows.Forms.GroupBox)) || (childCtl.GetType() == typeof(System.Windows.Forms.CheckBox)) || (childCtl.GetType() == typeof(System.Windows.Forms.Button)))
                    {
                        childCtl.Text = Localise.GetPhrase(childCtl.Text);
                    }

                    LocaliseControl(childCtl.Controls, toolTip); // Localize recursively for nested controls
                }
            }
            else // WPF controls
            {
                for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(control as System.Windows.DependencyObject); i++) // look for all child controls
                {
                    dynamic childCtl = System.Windows.Media.VisualTreeHelper.GetChild(control as System.Windows.DependencyObject, i);
                    if (IsSettingsExist(childCtl, "ToolTip")) // Check and change tooltip
                    {
                        if (childCtl.ToolTip != null)
                        {
                            childCtl.ToolTip = Localise.GetPhrase((string)childCtl.ToolTip);
                        }
                    }

                    if (((childCtl.GetType() == typeof(System.Windows.Controls.Label))) || ((childCtl.GetType() == typeof(System.Windows.Controls.GroupBox))) || ((childCtl.GetType() == typeof(System.Windows.Controls.CheckBox))) || ((childCtl.GetType() == typeof(System.Windows.Controls.Button))))
                    {
                        if ((childCtl.Content != null) && (childCtl.Content.GetType() == typeof(System.Windows.Controls.TextBlock))) // Check for nested labels
                        {
                            childCtl.Content.Text = Localise.GetPhrase(childCtl.Content.Text);
                        }
                        else
                        {
                            childCtl.Content = Localise.GetPhrase(childCtl.Content);
                        }
                    }

                    LocaliseControl(childCtl, null); // Localize recursively for nested controls
                }
            }
        }