我想使用箭头键或任何其他字母键来将标签从一个移动到下一个和从下到后移动。例: 假设我的tabcontrol有5个标签页,当我在标签页1时,我立即想要移动到2,从第二个到第三个和儿子。反之亦然。
答案 0 :(得分:0)
此代码将在选择任何标签后生效
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication28
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.tabControl1.KeyDown +=new KeyEventHandler(Tab_KeyDown);
}
private void Tab_KeyDown(object sender, KeyEventArgs e)
{
TabControl tabControl = sender as TabControl;
Console.WriteLine(tabControl.SelectedIndex.ToString());
if (e.KeyCode == Keys.Left)
{
if (tabControl.TabIndex > 0)
tabControl.TabIndex -= 1;
}
else if (e.KeyCode == Keys.Right)
{
int numberOfPages = tabControl.TabPages.Count;
if (tabControl.TabIndex < numberOfPages - 1)
tabControl.TabIndex += 1;
}
}
}
}