Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. tabcontrol with contextMenu

tabcontrol with contextMenu

Scheduled Pinned Locked Moved C#
comquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Erdinc27
    wrote on last edited by
    #1

    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?

    vemedya.com

    E 1 Reply Last reply
    0
    • E Erdinc27

      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?

      vemedya.com

      E Offline
      E Offline
      Erdinc27
      wrote on last edited by
      #2

      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;
      }
      }
      }

      vemedya.com

      OriginalGriffO 1 Reply Last reply
      0
      • E Erdinc27

        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;
        }
        }
        }

        vemedya.com

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        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 Tab

        My 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.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups