tabcontrol with contextMenu
-
hey guys..i have my MdiChild form tabbed in main form..and when i right click on the tabpage i want to close the one was right clicked..to do that i drag-drop a context menu and i choose that context menu from properties of my tabcontrol and wrote that codes
private void sekmeyiKapatToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (DetayForm item in this.MdiChildren)
{
if (item.tbpg.Equals(tabControl1.SelectedTab))
{
item.Select();
item.Close();
item.tbpg.Dispose();
}
}
}it works fine.but when i choose the first opened child form and try to close it all child forms are closed and it close all again when i right click not selected tab..what can i do?
-
hey guys..i have my MdiChild form tabbed in main form..and when i right click on the tabpage i want to close the one was right clicked..to do that i drag-drop a context menu and i choose that context menu from properties of my tabcontrol and wrote that codes
private void sekmeyiKapatToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (DetayForm item in this.MdiChildren)
{
if (item.tbpg.Equals(tabControl1.SelectedTab))
{
item.Select();
item.Close();
item.tbpg.Dispose();
}
}
}it works fine.but when i choose the first opened child form and try to close it all child forms are closed and it close all again when i right click not selected tab..what can i do?
hey again. i solved my problem like below.i found below code in web but i didnt understand exactly what GetTabRect() does?
private void tabControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
for (int i = 0; i < this.tabControl1.TabCount; i++)
{
if (this.tabControl1.GetTabRect(i).Contains(new Point(e.X, e.Y)))
{
this.tabControl1.SelectedIndex = i;
break;
}
}
}
}private void sekmeyiKapatToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (DetayForm item in this.MdiChildren)
{
if (item.tbpg.Equals(tabControl1.SelectedTab))
{
item.Close();
break;
}
}
} -
hey again. i solved my problem like below.i found below code in web but i didnt understand exactly what GetTabRect() does?
private void tabControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
for (int i = 0; i < this.tabControl1.TabCount; i++)
{
if (this.tabControl1.GetTabRect(i).Contains(new Point(e.X, e.Y)))
{
this.tabControl1.SelectedIndex = i;
break;
}
}
}
}private void sekmeyiKapatToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (DetayForm item in this.MdiChildren)
{
if (item.tbpg.Equals(tabControl1.SelectedTab))
{
item.Close();
break;
}
}
}When you don't know what something does, MDSN is the first place to look :GetTabRect method[^] A simple Google "GetTabRect MSDN" will find it for you... MSDN says "Returns the bounding rectangle for a specified tab in this tab control." which means it returns a Rectangle which contains the Tab part (on the tab list, has the text describing the tab).
My Tab
-----------
Other TabMy Tab Content ----------------------------------- It would return the rectangle containing "My Tab", but not "Other Tab" or "My Tab Content"
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.