コード例 #1
0
        /// <summary>
        /// This event will be generated when the user clicks on the playing grid,
        /// and checks if resize is required, places the user move, selects the best
        /// move for the computer and places the computer move.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
            int CoordX = 0;
            int CoordY = 0;

            if (e.Button == MouseButtons.Left)
            {
                int ScrollX = (AutoScrollPosition.X % CellSize);
                int ScrollY = (AutoScrollPosition.Y % CellSize);
                AutoScrollPosition.Offset(ScrollX, ScrollY);
                CoordX = (int)Math.Round(((-(decimal)AutoScrollPosition.X) / (decimal)CellSize), 0);
                CoordY = (int)Math.Round(((-(decimal)AutoScrollPosition.Y) / (decimal)CellSize), 0);
                Point CellCoord = new Point((e.X / CellSize) + CoordX, (e.Y / CellSize) + CoordY);
                if (GmBoard.GetSymbol(CellCoord) == Symbol.blank)
                {
                    Logic.MakeMove(CellCoord, UserSymbol);
                    Refresh();
                    if (Logic.CheckResult(CellCoord, UserSymbol))
                    {
                        GView.ShowResult(UserSymbol);
                        GmBoard.Clear();
                        ScreenFlag = Screens.exit;
                    }


                    if (CheckResizeRequired(CellCoord) == 1)
                    {
                        ResizeBoard();
                        Refresh();
                    }
                    else if (CheckResizeRequired(CellCoord) == 2)
                    {
                        IsTopLeft = true;
                        ResizeBoard();
                        Refresh();
                    }
                    Point ComputerPosition = Logic.SelectBestMove(ComputerSymbol);
                    Logic.MakeMove(ComputerPosition, ComputerSymbol);
                    Refresh();
                    if (Logic.CheckResult(ComputerPosition, ComputerSymbol))
                    {
                        GView.ShowResult(ComputerSymbol);
                        GmBoard.Clear();
                        ScreenFlag = Screens.exit;
                    }

                    Refresh();
                }
                else
                {
                    MessageBox.Show("Please make a valid move");
                }
            }

            else
            {
                MessageBox.Show("Right Click not allowed");
            }
        }
コード例 #2
0
        /// <summary>
        /// This method paints the board as well the symbols.
        /// </summary>
        /// <param name="e"></param>

        protected override void OnPaint(PaintEventArgs e)
        {
            if (IsTopLeft == true)
            {
                IsTopLeft = false;
                this.AutoScrollPosition = new Point(225, 225);
            }

            int dx = (AutoScrollPosition.X % CellSize);
            int dy = (AutoScrollPosition.Y % CellSize);

            AutoScrollPosition.Offset(AutoScrollPosition.X + dx, AutoScrollPosition.Y + dy);
            base.OnPaint(e);
            Matrix mx = new Matrix(1, 0, 0, 1, AutoScrollPosition.X, AutoScrollPosition.Y);

            e.Graphics.Transform = mx;
            if (ScreenFlag == Screens.game)
            {
                this.AutoScroll        = true;
                this.HScroll           = true;
                this.AutoScrollMinSize = new System.Drawing.Size(CellSize * BoardSize, CellSize * BoardSize);
                this.VScroll           = true;
                GView.ShowGrid(e.Graphics, BoardSize);
            }
            else if (ScreenFlag == Screens.exit)
            {
                this.AutoScrollPosition = new Point(0, 0);
                GoodBye.Visible         = true;
                this.AutoScroll         = false;
                Exit.Visible            = true;
                GameRestart.Visible     = true;
                GameHeading.Location    = new Point(160, 10);
                GameHeading.Visible     = true;
            }
        }
コード例 #3
0
 private void HMIForm_Scroll(object sender, ScrollEventArgs e)
 {
     if (Framework.IsStudioMode)
     {
         ShowDebugMessage(AutoScrollPosition.ToString());
         Invalidate();
     }
 }
コード例 #4
0
 /// <summary>
 ///     Handles the MouseFilterUp event of the mouseFilter control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">
 ///     The <see cref="MouseFilterEventArgs" /> instance containing the event data.
 /// </param>
 private void mouseFilter_MouseFilterUp(object sender, MouseFilterEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (_doTouchScroll && !AutoScrollPosition.Equals(_panelStartPoint) &&
             !_panelStartPoint.Equals(Point.Empty))
         {
             // don't fire Click-Event
             e.Handled = true;
         }
         _doTouchScroll   = false;
         _mouseStartPoint = Point.Empty;
         _panelStartPoint = Point.Empty;
     }
 }
コード例 #5
0
    void PanelOnPaint(object obj, PaintEventArgs pea)
    {
        Graphics grfx  = pea.Graphics;
        Brush    brush = new SolidBrush(ForeColor);

        int iCount = SysInfoStrings.Count;

        string[] astrLabels = SysInfoStrings.Labels;
        string[] astrValues = SysInfoStrings.Values;

        for (int i = 0; i < iCount; i++)
        {
            grfx.DrawString(astrLabels[i], Font, brush, 0, cySpace * i);
            grfx.DrawString(astrValues[i], Font, brush, cxCol, cySpace * i);
        }

        // test Выводим данные свойств класса ScrollableControl, наследуемого экземпляром panel
        grfx.DrawString(HScroll.ToString(), Font, brush, 400, 100);
        grfx.DrawString(VScroll.ToString(), Font, brush, 426, 100);
        grfx.DrawString(AutoScrollPosition.ToString(), Font, brush, 400, 100 + cySpace);
    }