void ColorPresetControl_Navigate(object sender, GridNavigateEventArgs args) { Control c = (Control)sender; TableLayoutPanelCellPosition navFrom = tableLayout.GetCellPosition(c); TableLayoutPanelCellPosition navTo = navFrom; bool navigateOffPresets = false; bool forward = false; switch (args.Navigate) { case GridNavigateEventArgs.Direction.Up: if (navFrom.Row <= 0) { navigateOffPresets = true; } else { navTo.Row--; } break; case GridNavigateEventArgs.Direction.Down: if (navFrom.Row >= tableLayout.RowCount - 1) { navigateOffPresets = true; forward = true; } else { navTo.Row++; } forward = true; break; case GridNavigateEventArgs.Direction.Left: if (navFrom.Column <= 0) { if (navFrom.Row <= 0) { navigateOffPresets = true; } else { navTo.Row--; navTo.Column = tableLayout.ColumnCount - 1; } } else { navTo.Column--; } break; case GridNavigateEventArgs.Direction.Right: if (navFrom.Column >= tableLayout.ColumnCount - 1) { if (navFrom.Row >= tableLayout.RowCount - 1) { forward = true; navigateOffPresets = true; } else { navTo.Column = 0; navTo.Row++; } } else { navTo.Column++; } break; default: break; } if (navigateOffPresets) { Navigate(new NavigateEventArgs(forward)); } else { tableLayout.GetControlFromPosition(navTo.Column, navTo.Row).Select(); } }
void ColorPresetControl_Navigate(object sender, GridNavigateEventArgs args) { Control c = (Control)sender; TableLayoutPanelCellPosition navFrom = tableLayout.GetCellPosition(c); TableLayoutPanelCellPosition navTo = navFrom; bool navigateOffPresets = false; bool forward = false; switch (args.Navigate) { case GridNavigateEventArgs.Direction.Up: if (navFrom.Row <= 0) { navigateOffPresets = true; } else { navTo.Row--; } break; case GridNavigateEventArgs.Direction.Down: if (navFrom.Row >= tableLayout.RowCount - 1) { navigateOffPresets = true; forward = true; } else { navTo.Row++; } forward = true; break; case GridNavigateEventArgs.Direction.Left: if (navFrom.Column <= 0) { if (navFrom.Row <= 0) { navigateOffPresets = true; } else { navTo.Row--; navTo.Column = tableLayout.ColumnCount - 1; } } else { navTo.Column--; } break; case GridNavigateEventArgs.Direction.Right: if (navFrom.Column >= tableLayout.ColumnCount - 1) { if (navFrom.Row >= tableLayout.RowCount - 1) { forward = true; navigateOffPresets = true; } else { navTo.Column = 0; navTo.Row++; } } else { navTo.Column++; } break; default: break; } if (navigateOffPresets) { Navigate(new NavigateEventArgs(forward)); } else { tableLayout.GetControlFromPosition(navTo.Column, navTo.Row).Select(); } }