当前位置: 首页>>代码示例>>C#>>正文


C# Position.IsEmpty方法代码示例

本文整理汇总了C#中Position.IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# Position.IsEmpty方法的具体用法?C# Position.IsEmpty怎么用?C# Position.IsEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Position的用法示例。


在下文中一共展示了Position.IsEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MoveActiveCell

        /// <summary>
        /// Move the active cell (focus), moving the row and column as specified.
        /// Try to set the focus using the first shift, if failed try to use the second shift (rowShift2, colShift2). 
        /// If rowShift2 or colShift2 is int.MaxValue the next start position is the maximum row or column, if is int.MinValue 0 is used, otherwise the current position is shifted using the specified value.
        /// This method is usually used for the Tab navigation using this code : MoveActiveCell(0,1,1,0);
        /// Returns true if the focus can be moved.
        /// Returns false if there aren't any cell to move.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="rowShift1"></param>
        /// <param name="colShift1"></param>
        /// <param name="rowShift2"></param>
        /// <param name="colShift2"></param>
        /// <returns></returns>
        public bool MoveActiveCell(Position start, int rowShift1, int colShift1, int rowShift2, int colShift2)
        {
            bool ret = MoveActiveCell(start, rowShift1, colShift1);

            if (ret)
                return true;
            else
            {
                Position newPosition = Position.Empty;

                //If there isn't a current active cell I try to put the focus on the 0, 0 cell.
                if (start.IsEmpty())
                {
                    newPosition = new Position(0, 0);
                    if (CanReceiveFocus(newPosition))
                        return Focus(newPosition, true);
                    else
                        start = newPosition;
                }

                int row;
                if (rowShift2 == int.MinValue)
                    row = 0;
                else if (rowShift2 == int.MaxValue)
                    row = Grid.Rows.Count - 1;
                else
                    row = start.Row + rowShift2;

                int column;
                if (colShift2 == int.MinValue)
                    column = 0;
                else if (colShift2 == int.MaxValue)
                    column = Grid.Columns.Count - 1;
                else
                    column = start.Column + colShift2;

                newPosition = new Position(row, column);

                if (newPosition == start || Grid.CompleteRange.Contains(newPosition) == false)
                    return false;

                if (CanReceiveFocus(newPosition))
                    return Focus(newPosition, true);
                else
                    start = newPosition;
                return MoveActiveCell(start, rowShift1, colShift1, rowShift2, colShift2);
            }
        }
开发者ID:zhuangyy,项目名称:Motion,代码行数:62,代码来源:SelectionBase.cs

示例2: Focus

        /// <summary>
        /// Change the ActivePosition (focus) of the grid.
        /// </summary>
        /// <param name="pCellToActivate"></param>
        /// <param name="pResetSelection">True to deselect the previous selected cells</param>
        /// <returns></returns>
        public bool Focus(Position pCellToActivate, bool pResetSelection)
        {
            //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells
            bool deselectOtherCells = false;
            if (pCellToActivate.IsEmpty() == false && pResetSelection)
                deselectOtherCells = true;

            pCellToActivate = Grid.PositionToStartPosition(pCellToActivate);

            //Check to see if the value is changed (note that I use the internal variable to see the actual stored value)
            if (pCellToActivate != ActivePosition)
            {
                //GotFocus Event Arguments
                Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate);
                CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus);
                ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                if (newCellToFocus != null)
                {
                    //Cell Focus Entering
                    Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs);
                    if (gotFocusEventArgs.Cancel)
                        return false;

                    //If the cell can't receive the focus stop the focus operation
                    if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false)
                        return false;
                }

                //If the new cell is valid I check if I can move the focus inside the grid
                if (newCellToFocus != null)
                {
                    //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false.
                    // This is useful for 2 reason:
                    //	-To validate the editor
                    //	-To check if I can move the focus on another cell
                    bool canFocus = Grid.Focus();
                    if (canFocus == false)
                        return false;
                }

                //If there is a cell with the focus fire the focus leave events
                if (IsActivePositionValid())
                {
                    //LostFocus Event Arguments
                    Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition);
                    CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus);
                    ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                    //Cell Focus Leaving
                    Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                        return false;

                    //Cell Lost Focus
                    OnCellLostFocus(lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                        return false;
                }
                else
                {
                    //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells)
                    // NOTE: in this case the focus event are not executed
                    m_ActivePosition = Position.Empty;
                }

                //Deselect previous selected cells
                if (deselectOtherCells)
                    ResetSelection(false);

                bool success;
                if (newCellToFocus != null)
                {
                    //Cell Got Focus
                    OnCellGotFocus(gotFocusEventArgs);

                    success = (!gotFocusEventArgs.Cancel);
                }
                else
                {
                    success = true;
                }

                //Fire a change event
                OnSelectionChanged(EventArgs.Empty);

                return success;
            }
            else
            {
                if (pCellToActivate.IsEmpty() == false)
                {
                    //I check if the grid still has the focus, otherwise I force it
                    if (Grid.ContainsFocus)
//.........这里部分代码省略.........
开发者ID:zhuangyy,项目名称:Motion,代码行数:101,代码来源:SelectionBase.cs

示例3: Focus

		// AlanP: Sep 2013  Added an optional parameter to specify that selection_changed events should be suppressed
        /// <summary>
		/// Change the ActivePosition (focus) of the grid.
		/// </summary>
		/// <param name="pCellToActivate"></param>
		/// <param name="pResetSelection">True to deselect the previous selected cells</param>
        /// <param name="suppressChangeEvent">Set to true to suppress Selection_Changed events</param>
		/// <returns></returns>
		public bool Focus(Position pCellToActivate, bool pResetSelection, bool suppressChangeEvent = false)
		{
			//If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells
			bool deselectOtherCells = false;
			if (pCellToActivate.IsEmpty() == false && pResetSelection)
				deselectOtherCells = true;

			//pCellToActivate = Grid.PositionToStartPosition(pCellToActivate);

			//Check to see if the value is changed (note that I use the internal variable to see the actual stored value)
			if (pCellToActivate != ActivePosition)
			{
				//GotFocus Event Arguments
				Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate);
				CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus);
				ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

				if (newCellToFocus != null)
				{
					//Cell Focus Entering
					Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs);
					if (gotFocusEventArgs.Cancel)
						return false;

					//If the cell can't receive the focus stop the focus operation
					if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false)
						return false;
				}

				//If the new cell is valid I check if I can move the focus inside the grid
				if (newCellToFocus != null)
				{
					//This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false.
					// This is useful for 2 reason:
					//	-To validate the editor
					//	-To check if I can move the focus on another cell
					bool canFocus = Grid.Focus(false);
                    if (canFocus == false)
                    {
                        // AlanP: Oct 2013
                        // The grid cannot be focused, which happens when we call SelectRowInGrid before the screen has been 'activated'.
                        // We still want to fire our SelectionChanged event
                        ResetSelection(false, true);
                        SelectCell(pCellToActivate, true);
                        return false;
                    }
				}

				RangeRegion oldFocusRegion = null;

				//If there is a cell with the focus fire the focus leave events
				if (IsActivePositionValid())
				{
					oldFocusRegion = new RangeRegion(ActivePosition);

					//LostFocus Event Arguments
					Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition);
					CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus);
					ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

					//Cell Focus Leaving
					Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs);
					if (lostFocusEventArgs.Cancel)
						return false;

					//Cell Lost Focus
					OnCellLostFocus(lostFocusEventArgs);
					if (lostFocusEventArgs.Cancel)
						return false;
				}
				else
				{
					//Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells)
					// NOTE: in this case the focus event are not executed
					m_ActivePosition = Position.Empty;
				}

				//Deselect previous selected cells
				if (deselectOtherCells)
					ResetSelection(false);

                // AlanP: Sep 2013  set our new member variable
                m_SuppressSelectionChangedEvent = suppressChangeEvent;

                bool success;
				if (newCellToFocus != null)
				{
					//Cell Got Focus
                    // AlanP: this will fire SelectionChanged
					OnCellGotFocus(gotFocusEventArgs);

					success = (!gotFocusEventArgs.Cancel);
//.........这里部分代码省略.........
开发者ID:Davincier,项目名称:openpetra,代码行数:101,代码来源:SelectionBase.cs


注:本文中的Position.IsEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。