private static bool Disable(Control control, User user) { Form owner = control.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { control.Enabled = true; string formName = owner.Name; string controlName = control.Name; PermissionCollection ps = user.GetAllPermissions(false); if (ps.ExceptControl(formName, controlName)) { control.Enabled = false; return(true); } else { foreach (Control c in control.Controls) { controlName = c.Name; if (ps.ExceptControl(formName, control.Name, controlName)) { c.Enabled = false; } else { ToolStrip ms = c as ToolStrip; if (ms != null) { ms.DisableForUser(user); } else { c.DisableForUser(user); } } } } } } return(false); }