タブページの右クリックでコンテキストメニューを表示するコードを作成しました。ユーザーがコンテキストメニューから[タブの削除]をクリックしたときに、実際にタブページを削除するにはどうすればよいですか?私はここまで到達しました。(unloadProfileは私のコンテキストメニュー項目です)。コンテキストメニューが関連付けているタブページを取得して削除する方法がわかりません。どんな助けでも大歓迎です。
// My Context Menu
private void tabControl_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// iterate through all the tab pages
for (int i = 0; i < tabControl.TabCount; i++)
{
// get their rectangle area and check if it contains the mouse cursor
Rectangle r = tabControl.GetTabRect(i);
if (r.Contains(e.Location))
{
// show the context menu here
this.contextMenuStrip1.Show(this.tabControl, e.Location);
}
}
}
}
// Context menu click event
private void unloadProfile_Click(object sender, EventArgs e)
{
// iterate through all the tab pages
for (int i = 0; i < tabControl.TabCount; i++)
{
}
}