Esempio n. 1
0
 public void SetPageName(string str, TabControl tc)
 {
     if (tc.InvokeRequired)
     {
         SetPageNameCallBack d = new SetPageNameCallBack(SetPageName);
         this.Invoke(d, new object[] { str, tc });
     }
     else
     {
         if (tc.Equals(ReceiveText))
         {
             str += "请求";
         }
         else
         {
             str += "响应";
         }
         tc.Controls[tc.Controls.Count - 1].Text = str;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Handles the PreviewMouseLeftButtonDown event of the TabControl.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private static void TabControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            TabControl tabControl = (TabControl)sender;

            TabTearOffBehavior._activeTabItem     = null;
            TabTearOffBehavior._dragStartPosition = default(Point);
            Point         position = e.GetPosition(tabControl);
            HitTestResult result   = VisualTreeHelper.HitTest(tabControl, position);

            if (result == null)
            {
                return;
            }
            TabItem tabItem = null;

            for (DependencyObject obj = result.VisualHit; obj != null; obj = VisualTreeHelper.GetParent(obj))
            {
                ButtonBase button = obj as ButtonBase;
                if (button != null)
                {
                    return;
                }
                if ((tabItem = obj as TabItem) != null)
                {
                    break;
                }
            }
            if (tabItem == null ||
                !tabControl.Equals(ItemsControl.ItemsControlFromItemContainer(tabItem)) ||
                !TabTearOffBehavior.GetHandler(tabControl).IsDragAllowed(tabControl.ItemContainerGenerator.ItemFromContainer(tabItem), tabControl, tabControl.ItemContainerGenerator.IndexFromContainer(tabItem)))
            {
                return;
            }
            TabTearOffBehavior._activeTabItem     = tabItem;
            TabTearOffBehavior._dragStartPosition = position;
            tabControl.PreviewMouseMove          += TabTearOffBehavior.TabControl_PreviewMouseMove;
            tabControl.PreviewMouseLeftButtonUp  += TabTearOffBehavior.TabControl_PreviewMouseLeftButtonUp;
            tabControl.MouseLeave       += TabTearOffBehavior.TabControl_MouseLeaveOrLostCapture;
            tabControl.LostMouseCapture += TabTearOffBehavior.TabControl_MouseLeaveOrLostCapture;
        }
Esempio n. 3
0
    private void TabItem_Drop(object sender, DragEventArgs e)
    {
      var tabItemTarget = e.Source as TabItem;
      var tabItemSource = e.Data.GetData(typeof(TabItem)) as TabItem;

      allowTabDrag = false;

      if (tabItemTarget != null && tabItemSource != null)
      {
        tiHoverTimer?.Stop();
        tiHoverTimer = null;
        if (!tabItemTarget.Equals(tabItemSource))
        {
          TabControl tabControlSource = tabItemSource.Parent as TabControl;
          String source = tabControlSource.Name;
          TabControl tabControlTarget = tabItemTarget.Parent as TabControl;
          String target = tabControlTarget.Name;
          if (tabControlSource.Equals(tabControlTarget))
          {
            int sourceIndex = tabControlTarget.Items.IndexOf(tabItemSource);
            int targetIndex = tabControlTarget.Items.IndexOf(tabItemTarget);

            tabControlTarget.Items.Remove(tabItemSource);
            tabControlTarget.Items.Insert(targetIndex, tabItemSource);

            tabControlTarget.Items.Remove(tabItemTarget);
            tabControlTarget.Items.Insert(sourceIndex, tabItemTarget);
          }
          else
          {
            int targetIndex = tabControlTarget.Items.IndexOf(tabItemTarget);

            tabControlSource.Items.Remove(tabItemSource);
            tabControlTarget.Items.Insert(targetIndex, tabItemSource);
          }
          tabItemSource.IsSelected = true;
          e.Handled = true;
        }
      }
    }