コード例 #1
0
 /// <summary>
 /// 重新创建
 /// </summary>
 public void ReCreate()
 {
     if (Native != null)
     {
         //清除单元格
         m_cells.Clear();
         //创建单元格
         for (int i = 1; i <= m_number * m_number; i++)
         {
             SquareCell cell = new SquareCell(this);
             cell.Number = i;
             m_cells.Add(cell);
         }
         Update();
     }
 }
コード例 #2
0
        /// <summary>
        /// 点击方法
        /// </summary>
        /// <param name="mp">鼠标坐标</param>
        /// <param name="button">按钮</param>
        /// <param name="clicks">点击次数</param>
        /// <param name="delta">滚轮值</param>
        public override void OnClick(POINT mp, MouseButtonsA button, int clicks, int delta)
        {
            base.OnClick(mp, button, clicks, delta);
            int cellSize = m_cells.Count;

            for (int i = 0; i < cellSize; i++)
            {
                SquareCell cell = m_cells[i];
                if (mp.x >= cell.Bounds.left && mp.x <= cell.Bounds.right &&
                    mp.y >= cell.Bounds.top && mp.y <= cell.Bounds.bottom)
                {
                    cell.Selected = true;
                }
                else
                {
                    cell.Selected = false;
                }
            }
            Invalidate();
        }
コード例 #3
0
        /// <summary>
        /// 重置布局
        /// </summary>
        public override void Update()
        {
            if (Native != null)
            {
                //中值
                int  mid    = m_number / 2 + 1;
                int  midnum = m_number * m_number / 2 + 1;
                RECT bounds = Bounds;
                int  width  = bounds.right - bounds.left;
                int  height = bounds.bottom - bounds.top;
                //左侧及上侧的坐标
                int left = (width - m_number * m_cellSize.cx) / 2;
                int top  = (height - m_number * m_cellSize.cy) / 2;
                int num  = 0;
                //方向状态
                int state = 0;
                //获取特殊旋转方向
                List <int> list     = new List <int>();
                int        cellSize = m_cells.Count;
                if (m_style == SquareStyle.Spiral)
                {
                    if (cellSize > 2)
                    {
                        int n = 2;
                        while (n <= cellSize)
                        {
                            list.Add(n);
                            int listSize = list.Count;
                            int last     = listSize > 1 ? list[listSize - 2] : 2;
                            n += list[listSize - 1] - last + 8;
                        }
                    }
                }
                //循环操作
                for (int i = 0; i < cellSize; i++)
                {
                    SquareCell cell  = m_cells[i];
                    SIZE       cSize = m_cellSize;
                    //螺旋
                    if (m_style == SquareStyle.Spiral)
                    {
                        //修正
                        if (i == 1)
                        {
                            state = 0;
                        }
                        else if (list.Contains(i))
                        {
                            state = 1;
                        }
                        //初始化
                        if (i == 0)
                        {
                            num = midnum;
                        }
                        else
                        {
                            switch (state)
                            {
                            //向左
                            case 0:
                                num = num - m_number;
                                break;

                            //向上
                            case 1:
                                num = num + 1;
                                break;

                            //向右
                            case 2:
                                num = num + m_number;
                                break;

                            //向下
                            case 3:
                                num = num - 1;
                                break;
                            }
                        }
                    }
                    //普通
                    else
                    {
                        num = cell.Number;
                    }
                    //获取列号和行号
                    int cindex = (num - 1) / m_number;
                    int rindex = m_number - (num % m_number == 0 ? m_number : num % m_number);
                    //获取横坐标和纵坐标
                    POINT cLocation = new POINT(left + m_cellSize.cx * cindex, top + m_cellSize.cy * rindex);
                    cell.Bounds = new RECT(cLocation.x, cLocation.y, cLocation.x + cSize.cx, cLocation.y + cSize.cy);
                    //主要
                    if (num == cindex * (m_number + 1) + 1 || num == cindex * (m_number - 1) + m_number)
                    {
                        cell.Style = SquareCellStyle.Major;
                        //螺旋
                        if (m_style == SquareStyle.Spiral)
                        {
                            if (num == cindex * (m_number + 1) + 1)
                            {
                                if (num >= midnum)
                                {
                                    state = 3;
                                }
                            }
                            else if (num == cindex * (m_number - 1) + m_number)
                            {
                                if (num < midnum)
                                {
                                    state = 2;
                                }
                                else
                                {
                                    state = 0;
                                }
                            }
                        }
                    }
                    //次要
                    else if ((num - mid) % m_number == 0 || (num >= (mid - 1) * m_number + 1 && num <= mid * m_number))
                    {
                        cell.Style = SquareCellStyle.Minor;
                    }
                }
            }
        }