/// <summary> /// Scans controls that are not contained by <c>Controls</c> /// collection, like <c>MenuItem</c>s, <c>StatusBarPanel</c>s /// and <c>ColumnHeader</c>s. /// </summary> /// <param name="form"> /// <c>ContainerControl</c> object to scan. /// </param> /// <param name="resources"> /// <c>ResourceManager</c> used to get localized resources. /// </param> protected virtual void ScanNonControls(System.Windows.Forms.ContainerControl containerControl, System.Resources.ResourceManager resources) { FieldInfo[] fieldInfo = containerControl.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < fieldInfo.Length; i++) { object obj = fieldInfo[i].GetValue(containerControl); string fieldName = fieldInfo[i].Name; if (obj is System.Windows.Forms.MenuItem) { System.Windows.Forms.MenuItem menuItem = (System.Windows.Forms.MenuItem)obj; menuItem.Text = (string)GetSafeValue(resources, fieldName + ".Text", menuItem.Text); } if (obj is System.Windows.Forms.ColumnHeader) { System.Windows.Forms.ColumnHeader header = (System.Windows.Forms.ColumnHeader)obj; header.Text = (string)(GetSafeValue(resources, fieldName + ".Text", header.Text)); header.TextAlign = (System.Windows.Forms.HorizontalAlignment)(GetSafeValue(resources, fieldName + ".TextAlign", header.TextAlign)); header.Width = (int)(GetSafeValue(resources, fieldName + ".Width", header.Width)); } if (obj is System.Windows.Forms.ToolBarButton) { System.Windows.Forms.ToolBarButton button = (System.Windows.Forms.ToolBarButton)obj; button.Enabled = (bool)(GetSafeValue(resources, fieldName + ".Enabled", button.Enabled)); button.ImageIndex = (int)(GetSafeValue(resources, fieldName + ".ImageIndex", button.ImageIndex)); button.ToolTipText = (string)(GetSafeValue(resources, fieldName + ".ToolTipText", button.ToolTipText)); button.Visible = (bool)(GetSafeValue(resources, fieldName + ".Visible", button.Visible)); } } }
public object Clone(ContainerControl owner) { MetroStyleManager clonedManager = Clone() as MetroStyleManager; if (owner is IMetroForm) { clonedManager.Owner = owner; ((IMetroForm)owner).StyleManager = clonedManager; Type parentForm = owner.GetType(); FieldInfo fieldInfo = parentForm.GetField("components", BindingFlags.Instance | BindingFlags.NonPublic); IContainer mother = (IContainer)fieldInfo.GetValue(owner); // Check for a helper component foreach (Component obj in mother.Components) { if (obj is IMetroComponent) { ApplyTheme((IMetroComponent)obj); } if (obj.GetType() == typeof(MetroContextMenu)) { ApplyTheme((MetroContextMenu)obj); } } } return clonedManager; }
/// <summary> /// Scans controls that are not contained by <c>Controls</c> /// collection, like <c>MenuItem</c>s, <c>StatusBarPanel</c>s /// and <c>ColumnHeader</c>s. /// </summary> /// <param name="form"> /// <c>ContainerControl</c> object to scan. /// </param> /// <param name="resources"> /// <c>ResourceManager</c> used to get localized resources. /// </param> protected virtual void ScanNonControls(System.Windows.Forms.ContainerControl containerControl, System.Resources.ResourceManager resources) { FieldInfo[] fieldInfo = containerControl.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < fieldInfo.Length; i++) { object obj = fieldInfo[i].GetValue(containerControl); string fieldName = fieldInfo[i].Name; if (obj is System.Windows.Forms.MenuItem) { System.Windows.Forms.MenuItem menuItem = (System.Windows.Forms.MenuItem)obj; menuItem.Enabled = (bool)(GetSafeValue(resources, fieldName + ".Enabled", menuItem.Enabled)); menuItem.Shortcut = (System.Windows.Forms.Shortcut)(GetSafeValue(resources, fieldName + ".Shortcut", menuItem.Shortcut)); menuItem.ShowShortcut = (bool)(GetSafeValue(resources, fieldName + ".ShowShortcut", menuItem.ShowShortcut)); menuItem.Text = (string)GetSafeValue(resources, fieldName + ".Text", menuItem.Text); menuItem.Visible = (bool)(GetSafeValue(resources, fieldName + ".Visible", menuItem.Visible)); } if (obj is System.Windows.Forms.StatusBarPanel) { System.Windows.Forms.StatusBarPanel panel = (System.Windows.Forms.StatusBarPanel)obj; panel.Alignment = (System.Windows.Forms.HorizontalAlignment)(GetSafeValue(resources, fieldName + ".Alignment", panel.Alignment)); panel.Icon = (System.Drawing.Icon)(GetSafeValue(resources, fieldName + ".Icon", panel.Icon)); panel.MinWidth = (int)(GetSafeValue(resources, fieldName + ".MinWidth", panel.MinWidth)); panel.Text = (string)(GetSafeValue(resources, fieldName + ".Text", panel.Text)); panel.ToolTipText = (string)(GetSafeValue(resources, fieldName + ".ToolTipText", panel.ToolTipText)); panel.Width = (int)(GetSafeValue(resources, fieldName + ".Width", panel.Width)); } if (obj is System.Windows.Forms.ColumnHeader) { System.Windows.Forms.ColumnHeader header = (System.Windows.Forms.ColumnHeader)obj; header.Text = (string)(GetSafeValue(resources, fieldName + ".Text", header.Text)); header.TextAlign = (System.Windows.Forms.HorizontalAlignment)(GetSafeValue(resources, fieldName + ".TextAlign", header.TextAlign)); header.Width = (int)(GetSafeValue(resources, fieldName + ".Width", header.Width)); } if (obj is System.Windows.Forms.ToolBarButton) { System.Windows.Forms.ToolBarButton button = (System.Windows.Forms.ToolBarButton)obj; button.Enabled = (bool)(GetSafeValue(resources, fieldName + ".Enabled", button.Enabled)); button.ImageIndex = (int)(GetSafeValue(resources, fieldName + ".ImageIndex", button.ImageIndex)); button.Text = (string)(GetSafeValue(resources, fieldName + ".Text", button.Text)); button.ToolTipText = (string)(GetSafeValue(resources, fieldName + ".ToolTipText", button.ToolTipText)); button.Visible = (bool)(GetSafeValue(resources, fieldName + ".Visible", button.Visible)); } if (obj is Telerik.WinControls.UI.RibbonTab) { Telerik.WinControls.UI.RibbonTab tab = (Telerik.WinControls.UI.RibbonTab)obj; tab.Enabled = (bool)(GetSafeValue(resources, fieldName + ".Enabled", tab.Enabled)); tab.Text = (string)(GetSafeValue(resources, fieldName + ".Text", tab.Text)); tab.ToolTipText = (string)(GetSafeValue(resources, fieldName + ".ToolTipText", tab.ToolTipText)); } if (obj is Telerik.WinControls.UI.RadRibbonBarGroup) { Telerik.WinControls.UI.RadRibbonBarGroup group = (Telerik.WinControls.UI.RadRibbonBarGroup)obj; group.Enabled = (bool)(GetSafeValue(resources, fieldName + ".Enabled", group.Enabled)); group.Text = (string)(GetSafeValue(resources, fieldName + ".Text", group.Text)); group.ToolTipText = (string)(GetSafeValue(resources, fieldName + ".ToolTipText", group.ToolTipText)); } if (obj is Telerik.WinControls.UI.RadButtonElement) { Telerik.WinControls.UI.RadButtonElement button = (Telerik.WinControls.UI.RadButtonElement)obj; button.Enabled = (bool)(GetSafeValue(resources, fieldName + ".Enabled", button.Enabled)); button.Text = (string)(GetSafeValue(resources, fieldName + ".Text", button.Text)); button.ToolTipText = (string)(GetSafeValue(resources, fieldName + ".ToolTipText", button.ToolTipText)); } if (obj is Telerik.WinControls.UI.RadGridView) { Telerik.WinControls.UI.RadGridView gridview = (Telerik.WinControls.UI.RadGridView)obj; if (gridview.ColumnCount == 0) { return; } foreach (Telerik.WinControls.UI.GridViewColumn column in gridview.Columns) { // Resource key: GridViewID.ColumnId.HeaderText column.HeaderText = (string)(GetSafeValue(resources, fieldName + "." + column.Name + ".HeaderText", column.HeaderText)); } } } }