コード例 #1
0
        private void ShipDragDrop(TableLayoutPanel t_myships, int shipcount, object sender, DragEventArgs e)
        {
            var cellPos = GetRowColIndex(t_myships, t_myships.PointToClient(Cursor.Position));

            if (cellPos == null)//out of range
            {
                MessageBox.Show("out of range");
                return;
            }
            if (shipcount == 1)
            {
                if (shipCount1[ship_lg - 1] == 1)
                {
                    MessageBox.Show("Ship already used!");
                    return;
                }
            }
            else
            {
                if (shipCount2[ship_lg - 1] == 1)
                {
                    MessageBox.Show("Ship already used!");
                    return;
                }
            }
            if (cellPos != null && inBound(cellPos, ship_lg, direc) && CheckShipLoc(t_myships, cellPos, ship_lg, direc))
            {
                if (direc == "" || direc == "right")
                {
                    for (int r = 0; r < ship_lg; r++)
                    {
                        Button b = (Button)t_myships.GetControlFromPosition(cellPos.Value.X + r, cellPos.Value.Y);
                        b.Text = "O";
                    }
                }
                else
                {
                    for (int r = 0; r < ship_lg; r++)
                    {
                        Button b = (Button)t_myships.GetControlFromPosition(cellPos.Value.X, cellPos.Value.Y + r);
                        b.Text = "O";
                    }
                }

                //TO DO :SAVE TO LOC ARRAY
                if (shipcount == 1)
                {
                    shipCount1[ship_lg - 1] = 1;
                }
                else
                {
                    shipCount2[ship_lg - 1] = 1;
                }
                //TO DO : REMOVE ITEM FROM LIST
            }
            else
            {
                MessageBox.Show("relocate ship");
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: rimbreaker/The_knight
 public void clickOnSpace(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left && isEditMode == true)
     {
         if (mode == 2)
         {
             if (panel.GetControlFromPosition(panel.GetColumn((PictureBox)sender), panel.GetRow((PictureBox)sender)).BackColor != Color.Maroon)
             {
                 panel.GetControlFromPosition(panel.GetColumn((PictureBox)sender), panel.GetRow((PictureBox)sender)).BackColor = Color.Maroon;
             }
         }
         else
         {
             if (panel.GetControlFromPosition(panel.GetColumn((PictureBox)sender), panel.GetRow((PictureBox)sender)).BackColor != Color.ForestGreen)
             {
                 panel.GetControlFromPosition(panel.GetColumn((PictureBox)sender), panel.GetRow((PictureBox)sender)).BackColor = Color.ForestGreen;
             }
         }
     }
     else if (isEditMode == true)
     {
         contextMenuStrip1.Show(panel.GetControlFromPosition(panel.GetColumn((PictureBox)sender), panel.GetRow((PictureBox)sender)), e.Location.X, e.Location.Y);
         np = (Point)GetRowColIndex(panel, panel.PointToClient(Cursor.Position));
     }
 }
コード例 #3
0
        void onMouseMove()
        {
            Point mousePositionOnPanel;

            mousePositionOnPanel = tabeleLayout.PointToClient(Cursor.Position);
            labelX.Text          = "X Y" + mousePositionOnPanel;
            drawLine(g, mousePositionOnPanel);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ntvy95/DustCollector
        public static Point GetCellPositionFromCursorPosition(this TableLayoutPanel tlp)
        {
            Point Position = tlp.PointToClient(Cursor.Position);
            int   Column   = Convert.ToInt32(Math.Floor(
                                                 Convert.ToDouble(Position.X) / tlp.Width * tlp.ColumnCount)),
                  Row = Convert.ToInt32(Math.Floor(
                                            Convert.ToDouble(Position.Y) / tlp.Height * tlp.RowCount));

            return(new Point(Column, Row));
        }
コード例 #5
0
        private void MouseLeave()
        {
            System.Drawing.Point mouseLocation = mainTable.PointToClient(Cursor.Position);
            int left   = deleteEntryButton.Left;
            int right  = deleteEntryButton.Right;
            int top    = deleteEntryButton.Top;
            int bottom = deleteEntryButton.Bottom;

            if (!(mouseLocation.X > left && mouseLocation.X < right && mouseLocation.Y > top && mouseLocation.Y < bottom))
            {
                mainTable.BackColor = System.Drawing.Color.FromArgb(0);
                deleteEntryButton.Hide();
            }
        }
コード例 #6
0
        private void TableLayoutPanel_DragOver(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(Button)))
            {
                return;
            }

            e.Effect = e.AllowedEffect;
            var draggedButton = (Button)e.Data.GetData(typeof(Button));

            var pt     = tableLayoutPanel.PointToClient(new Point(e.X, e.Y));
            var button = (Button)tableLayoutPanel.GetChildAtPoint(pt);

            if (button != null)
            {
                var pos = tableLayoutPanel.GetPositionFromControl(button);
                tableLayoutPanel.Controls.Add(draggedButton, pos.Column, pos.Row);
                draggedButton.Tag = null;
            }
        }
コード例 #7
0
        private TableLayoutPanelCellPosition GetCellPosition(TableLayoutPanel panel)
        {
            //mouse position
            Point p = panel.PointToClient(Control.MousePosition);
            //Cell position
            TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition(0, 0);
            //Panel size.
            Size size = panel.Size;
            //average cell size.
            SizeF cellAutoSize = new SizeF(size.Width / panel.ColumnCount, size.Height / panel.RowCount);

            //Get the cell row.
            //y coordinate
            float y = 0;
            for (int i = 0; i < panel.RowCount; i++)
            {
                //Calculate the summary of the row heights.
                SizeType type = panel.RowStyles[i].SizeType;
                float height = panel.RowStyles[i].Height;
                switch (type)
                {
                    case SizeType.Absolute:
                        y += height;
                        break;
                    case SizeType.Percent:
                        y += height / 100 * size.Height;
                        break;
                    case SizeType.AutoSize:
                        y += cellAutoSize.Height;
                        break;
                }
                //Check the mouse position to decide if the cell is in current row.
                if ((int)y > p.Y)
                {
                    pos.Row = i;
                    break;
                }
            }

            //Get the cell column.
            //x coordinate
            float x = 0;
            for (int i = 0; i < panel.ColumnCount; i++)
            {
                //Calculate the summary of the row widths.
                SizeType type = panel.ColumnStyles[i].SizeType;
                float width = panel.ColumnStyles[i].Width;
                switch (type)
                {
                    case SizeType.Absolute:
                        x += width;
                        break;
                    case SizeType.Percent:
                        x += width / 100 * size.Width;
                        break;
                    case SizeType.AutoSize:
                        x += cellAutoSize.Width;
                        break;
                }
                //Check the mouse position to decide if the cell is in current column.
                if ((int)x > p.X)
                {
                    pos.Column = i;
                    break;
                }
            }

            //return the mouse position.
            return pos;
        }