public void InsertTab(int index, string title) { var tab = new SheetTabItem(this, title) { Height = this.canvas.Height, }; this.canvas.Width += tab.Width + 1; this.canvas.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(tab.Width + 1) }); this.canvas.Children.Add(tab); Grid.SetColumn(tab, index); tab.MouseDown += (s, e) => { var arg = new SheetTabMouseEventArgs() { Handled = false, Location = e.GetPosition(this), Index = index, MouseButtons = WPFUtility.ConvertToUIMouseButtons(e), }; if (this.TabMouseDown != null) { this.TabMouseDown(this, arg); } if (!arg.Handled) { this.SelectedIndex = index; } }; if (this.canvas.Children.Count == 1) { tab.IsSelected = true; } }
private void Tab_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var index = this.canvas.Children.IndexOf((UIElement)sender); var arg = new SheetTabMouseEventArgs() { Handled = false, Location = e.GetPosition(this), Index = index, MouseButtons = WPFUtility.ConvertToUIMouseButtons(e), }; if (this.TabMouseDown != null) { this.TabMouseDown(this, arg); } if (!arg.Handled) { this.SelectedIndex = index; } }
/// <summary> /// Override system mouse down event /// </summary> /// <param name="e">mouse down event argument</param> protected override void OnMouseDown(MouseEventArgs e) { this.leftScrollPressed = this.rightScrollPressed = false; // scroll buttons if (e.X < leftPadding) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { var hwp = leftPadding / 2; if (e.X < hwp) { this.leftScrollPressed = true; } else { this.rightScrollPressed = true; } if (this.leftScrollPressed || this.rightScrollPressed) { if (timer == null) { timer = new Timer { Interval = 10 }; timer.Tick += timer_Tick; } timer.Enabled = true; } } else if (e.Button == System.Windows.Forms.MouseButtons.Right) { if (this.SheetListClick != null) { this.SheetListClick(this, null); } } } // splitter else if (e.X > this.ClientRectangle.Right - 8) { this.splitterPressed = true; this.Capture = true; } else if (e.X < this.ClientRectangle.Right - 8 && e.X > this.ClientRectangle.Right - 28 && this.NewButtonVisible) { if (this.NewSheetClick != null) { this.NewSheetClick(this, null); } } else { int index = GetItemByPoint(e.X); if (index != -1) { if (selectedIndex != index) { selectedIndex = index; Invalidate(); if (SelectedIndexChanged != null) { SelectedIndexChanged(this, null); } } bool processed = false; if (this.TabMouseDown != null) { var arg = new SheetTabMouseEventArgs { Location = e.Location, MouseButtons = (unvell.ReoGrid.Interaction.MouseButtons)e.Button, Handled = false, }; this.TabMouseDown(this, arg); processed = arg.Handled; } if (!processed) { movingStartIndex = index; movingHoverIndex = -1; Capture = true; } } } }