public void MoveCursorToTarget(TabCursor cursor) { double cursorPosition = (cursor.Value - _minX) / (_maxX - _minX); if (cursorPosition < 0 || double.IsNaN(cursorPosition)) { cursorPosition = 0; } else if (cursorPosition > 1) { cursorPosition = 1; } // 减去控件宽度的一半保证游标控件中间对齐到位置 int cursorXPosition = (int)Math.Round(PlotRealX + cursorPosition * PlotRealWidth) - (cursor.Control.Width - 1) / 2; int cursorYPosition = (int)PlotRealY; if (cursor.Control.Location.X != cursorXPosition || cursor.Control.Location.Y != cursorYPosition) { cursor.Control.Location = new Point(cursorXPosition, cursorYPosition); } if (PlotRealHeight != cursor.Control.Height) { cursor.Control.Height = PlotRealHeight; } }
private void TabClicked(object sender, RoutedEventArgs e) { var index = int.Parse(((Button)e.Source).Uid); ProfilePan.Visibility = Visibility.Collapsed; RemoveWhiteBackground(button: profileButton); RemoveWhiteBackground(button: profileButton1); var ta = new ThicknessAnimation { From = TabCursor.Margin, To = new Thickness(120 * index, 0, 0, 10), Duration = new Duration(TimeSpan.FromSeconds(0.2)) }; TabCursor.BeginAnimation(MarginProperty, ta); DataContext = index switch { 0 => new HomeVM(this, ActiveUser), 1 when ActiveUser.Username == "Anonimas" => new VendorsVM(), 1 => new MyServicesVM(ActiveUser), 2 when ActiveUser.Username == "Anonimas" => new FaqVM(), 2 => new AddServiceVM(ActiveUser), _ => new AboutVM() }; }
private void dataGridView_cursorInfo_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (_isInternalOperation || e.RowIndex < 0 || e.ColumnIndex < 0) { return; } _isInternalOperation = true; object changedValue = dataGridView_cursorInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; TabCursor changeCursor = _cursors[e.RowIndex]; switch (e.ColumnIndex) { // case CursorEnableIndex: // changeCursor.Enabled = (bool)changedValue; // break; // case CursorColorIndex: // break; case CursorNameIndex: if (null != changedValue && _cursors.All(cursor => !cursor.Name.Equals(changedValue))) { changeCursor.Name = changedValue.ToString(); } dataGridView_cursorInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = changeCursor.Name; break; case CursorSeriesIndex: string seriesName = dataGridView_cursorInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); int index = SeriesIndex.Items.IndexOf(seriesName); _cursors[e.RowIndex].SeriesIndex = index - 1; double yValue = _cursors[e.RowIndex].YValue; dataGridView_cursorInfo.Rows[e.RowIndex].Cells[CursorYValueIndex].Value = double.IsNaN(yValue) ? string.Empty : yValue.ToString(); break; case CursorValueIndex: double xValue; if (double.TryParse(changedValue.ToString(), out xValue)) { changeCursor.Value = xValue; } dataGridView_cursorInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = changeCursor.Value; break; default: break; } _isInternalOperation = false; }
public void RefreshCursorValue(TabCursor cursor) { // 游标真实位置需要加上cursor视图和控件本身像素差的偏移 int cursorPosition = cursor.Control.Location.X + TabCursorControl.ViewPixelOffset; double valueRatio = (cursorPosition - PlotRealX) / PlotRealWidth; double value = (_maxX - _minX) * valueRatio + _minX; if (value > _maxX) { value = _maxX; } else if (value < _minX) { value = _minX; } cursor.Value = value; }
private void dataGridView_cursorInfo_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (_isInternalOperation || e.RowIndex < 0 || e.ColumnIndex < 0) { return; } _isInternalOperation = true; TabCursor changeCursor = _cursors[e.RowIndex]; switch (e.ColumnIndex) { case CursorEnableIndex: // dataGridView_cursorInfo.EndEdit(); changeCursor.Enabled = !changeCursor.Enabled; dataGridView_cursorInfo.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = changeCursor.Enabled; // dataGridView_cursorInfo.EndEdit(); break; case CursorColorIndex: ColorDialog loColorForm = new ColorDialog(); if (loColorForm.ShowDialog() == DialogResult.OK) { changeCursor.Color = loColorForm.Color; DataGridViewRow row = dataGridView_cursorInfo.Rows[e.RowIndex]; row.Cells[CursorColorIndex].Style.BackColor = changeCursor.Color; row.Cells[CursorColorIndex].Style.SelectionBackColor = changeCursor.Color; } break; // case CursorNameIndex: // break; // case CursorValueIndex: // break; default: break; } _isInternalOperation = false; }
private void button_delete_Click(object sender, EventArgs e) { if (0 == dataGridView_cursorInfo.SelectedCells.Count) { return; } HashSet <int> rowIndexes = new HashSet <int>(); foreach (DataGridViewCell selectCell in dataGridView_cursorInfo.SelectedCells) { rowIndexes.Add(selectCell.RowIndex); } foreach (int rowIndex in rowIndexes) { string cursorName = dataGridView_cursorInfo.Rows[rowIndex].Cells[CursorNameIndex].Value.ToString(); TabCursor deleteCursor = _cursors.First(item => item.Name.Equals(cursorName)); if (null != deleteCursor) { _cursors.Remove(deleteCursor); } } RefreshCursorInfo(); }