static private void SecureToolStripDropDownItems(System.Windows.Forms.ToolStripMenuItem menuStrip, bool securityState) { foreach (ToolStripMenuItem item in menuStrip.DropDownItems) { if (item.HasDropDownItems) { SecureToolStripDropDownItems(item, securityState); } if (CWProductProtection.IsObjectControlled(item.Name)) { item.Enabled = securityState; } } }
/// <summary> /// Secure all controlled controls. /// It is left up to the user to determine when /// to call this method. /// </summary> /// <param name="formToSecure"></param> static private void SecureControls(System.Windows.Forms.Form formToSecure, bool securityState) { foreach (Control control in formToSecure.Controls) { if (CWProductProtection.IsObjectControlled(control.Name)) { control.Enabled = securityState; } if (control.Enabled && control.GetType() == typeof(System.Windows.Forms.MenuStrip)) { foreach (ToolStripMenuItem menuItem in ((MenuStrip)control).Items) { SecureMenuStrip(menuItem, securityState); } } } }