/// <summary> /// Event handler for the "Add Tab" verb. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="ea"> /// Some <see cref="EventArgs"/>. /// </param> private void AddTab(object sender, EventArgs ea) { IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost)); if (dh != null) { int selTab = _tabControl.SelectedIndex; string name = GetNewTabName(); ImageTabPage itp = dh.CreateComponent(typeof(ImageTabPage), name) as ImageTabPage; itp._index = _tabControl.TabPages.Count;// (_tabControl.Controls as ImageTabControl.ControlCollection).Count; itp.Text = "Tab" + itp._index; _tabControl.TabPages.Add(itp); //_tabControl.Controls.Add(itp); //ytp.Name = _tabControl.Name + "_Tab" + _tabControl.Controls.Count; //ytp.Text = "Tab"+_tabControl.TabPages.Count; //(_tabControl.Controls as ImageTabControl.ControlCollection).Add(itp); _tabControl.CalculateTabLengths(); if (_tabControl.SelectedIndex < 0) { _tabControl.SelectedIndex = itp.Index; //MessageBox.Show("index:" + ytp.Index); RaiseComponentChanging(TypeDescriptor.GetProperties(Control)["SelectedIndex"]); RaiseComponentChanged(TypeDescriptor.GetProperties(Control)["SelectedIndex"], selTab, _tabControl.SelectedIndex); } dh.Activate(); } }
/// <summary> /// Overridden. Inherited from <see cref="ControlDesigner"/>. /// </summary> /// <param name="m"> /// The message. /// </param> /// <remarks> /// Checks for WM_LBUTTONDOWN events and uses that to /// select the appropriate tab in the <see cref="ImageTabControl"/>. /// </remarks> protected override void WndProc(ref Message m) { try { int x = 0; int y = 0; if (_tabControl.Created && m.HWnd == _tabControl.Handle) { switch (m.Msg) { case WM_LBUTTONDOWN: x = (m.LParam.ToInt32() << 16) >> 16; y = m.LParam.ToInt32() >> 16; int oi = _tabControl.SelectedIndex; ImageTabPage ot = _tabControl.SelectedTab; if (_tabControl.ScrollButtonStyle == YaScrollButtonStyle.Always && _tabControl.GetLeftScrollButtonRect().Contains(x, y)) { _tabControl.ScrollTabs(-10); } else if (_tabControl.ScrollButtonStyle == YaScrollButtonStyle.Always && _tabControl.GetRightScrollButtonRect().Contains(x, y)) { _tabControl.ScrollTabs(10); } else { for (int i = 0; i < (_tabControl.Controls as ImageTabControl.ControlCollection).Count; i++) { Rectangle r = _tabControl.GetTabRect(_tabControl.TabPages[i] as ImageTabPage); if (r.Contains(x, y)) { _tabControl.SelectedIndex = i; RaiseComponentChanging(TypeDescriptor.GetProperties(Control)["SelectedIndex"]); RaiseComponentChanged(TypeDescriptor.GetProperties(Control)["SelectedIndex"], oi, i); break; } } } break; case WM_LBUTTONDBLCLK: x = (m.LParam.ToInt32() << 16) >> 16; y = m.LParam.ToInt32() >> 16; if (_tabControl.ScrollButtonStyle == YaScrollButtonStyle.Always && _tabControl.GetLeftScrollButtonRect().Contains(x, y)) { _tabControl.ScrollTabs(-10); } else if (_tabControl.ScrollButtonStyle == YaScrollButtonStyle.Always && _tabControl.GetRightScrollButtonRect().Contains(x, y)) { _tabControl.ScrollTabs(10); } return; } } } finally { base.WndProc(ref m); } }
/// <summary> /// Event handler for the "Remove Tab" verb. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="ea"> /// Some <see cref="EventArgs"/>. /// </param> private void RemoveTab(object sender, EventArgs ea) { IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost)); if (dh != null) { int i = _tabControl.SelectedIndex; if (i > -1) { ImageTabPage ytp = _tabControl.SelectedTab; (_tabControl.Controls as ImageTabControl.ControlCollection).Remove(ytp); dh.DestroyComponent(ytp); RaiseComponentChanging(TypeDescriptor.GetProperties(Control)["SelectedIndex"]); RaiseComponentChanged(TypeDescriptor.GetProperties(Control)["SelectedIndex"], i, 0); } } }