internal ToolStripItem SelectNextToolStripItem(ToolStripItem start, bool forward) { var collection = Items; if (collection.Count == 0) { return(null); } if (collection.Any(item => item.CanSelect) == false) { return(null); } if (collection.Count == 1) { collection[0].Select(); return(collection[0]); } var nextItem = start; if (nextItem == null) { nextItem = forward ? collection[0] : collection[collection.Count - 1]; } else { var currentIndex = collection.IndexOf(nextItem); var nextIndex = forward ? currentIndex + 1 : currentIndex - 1; if (nextIndex < 0) { nextIndex = collection.Count - 1; } if (nextIndex >= collection.Count) { nextIndex = 0; } nextItem = collection[nextIndex]; } if (nextItem.CanSelect == false) { nextItem = SelectNextToolStripItem(nextItem, forward); } if (start != null) { start.Unselect(); } if (nextItem != null) { nextItem.Select(); } return(nextItem); }