Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从关联菜单中删除选项卡页_C#_Contextmenu_Tabcontrol_Tabpage - Fatal编程技术网

C# 如何从关联菜单中删除选项卡页

C# 如何从关联菜单中删除选项卡页,c#,contextmenu,tabcontrol,tabpage,C#,Contextmenu,Tabcontrol,Tabpage,我已经编写了在我的选项卡页面上右键单击时显示上下文菜单的代码。当用户从上下文菜单中单击“删除选项卡”时,我将如何实际删除选项卡页?我已经走了这么远。(unloadProfile是我的上下文菜单项)。我不确定如何获取上下文菜单关联的选项卡页以将其删除。感谢您的帮助 // My Context Menu private void tabControl_MouseClick(object sender, MouseEventArgs e) { if (e.Button == M

我已经编写了在我的选项卡页面上右键单击时显示上下文菜单的代码。当用户从上下文菜单中单击“删除选项卡”时,我将如何实际删除选项卡页?我已经走了这么远。(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++)
        {

        }
    }
//我的上下文菜单
私有无效选项卡控件\鼠标单击(对象发送者,鼠标目标)
{
if(e.Button==MouseButtons.Right)
{
//遍历所有选项卡页面
for(int i=0;i
我不认为这是一种正确的方法,但它是有效的

在tabControl1\u MouseClick(object sender,MouseEventArgs e)事件中,将menustrip的Tag属性设置为选中的TabPage

// show the context menu here
this.contextMenuStrip1.Tag = this.tabControl1.TabPages[i];
this.contextMenuStrip1.Show(this.tabControl1, e.Location);
然后在removeTabToolStripMenuItem_中单击(对象发送者,EventArgs e)事件使用Tag属性删除选项卡页面

this.tabControl1.TabPages.Remove(this.contextMenuStrip1.Tag as TabPage);

空检查会很好:)希望有帮助。

我认为这不是一种正确的方法,但它是有效的

在tabControl1\u MouseClick(object sender,MouseEventArgs e)事件中,将menustrip的Tag属性设置为选中的TabPage

// show the context menu here
this.contextMenuStrip1.Tag = this.tabControl1.TabPages[i];
this.contextMenuStrip1.Show(this.tabControl1, e.Location);
然后在removeTabToolStripMenuItem_中单击(对象发送者,EventArgs e)事件使用Tag属性删除选项卡页面

this.tabControl1.TabPages.Remove(this.contextMenuStrip1.Tag as TabPage);

空检查会很好:)希望能有帮助。

-哇,我被这个吓坏了。。部分代码对我来说没有意义,例如使用
标记作为
选项卡页面
。但很显然,它是有效的+成功1:)-哇,我被这个吓坏了。。部分代码对我来说没有意义,例如使用
标记作为
选项卡页面
。但很显然,它是有效的+1.成功的理由:)