Is there any code for the PageUp and PageDown keys to navigate to the previous and next textboxes in addition to the Up and Down arrow keys in c sharp , .net framework .
private void Control_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown)
{
if (sender is TextBox currentTextBox)
{
// Get the index of the current textbox in the parent container's control collection
int currentIndex = currentTextBox.Parent.Controls.IndexOf(currentTextBox);
// Calculate the index of the previous or next textbox based on the key pressed
int newIndex = e.KeyCode == Keys.PageUp ? currentIndex - 1 : currentIndex + 1;
// Check if the new index is within the valid range of textboxes
if (newIndex >= 0 && newIndex < currentTextBox.Parent.Controls.Count)
{
TextBox newTextBox = (TextBox)currentTextBox.Parent.Controls[newIndex];
// Set focus to the previous or next textbox
newTextBox.Focus();
}
}
}
}