本文整理汇总了C#中System.Windows.Forms.Button.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Button.GetLength方法的具体用法?C# Button.GetLength怎么用?C# Button.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Button
的用法示例。
在下文中一共展示了Button.GetLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: reArrangeButtonPosition
public void reArrangeButtonPosition(Button []buttonArr, int startPositionY, int formWidth)
{
int buttonCount = 0;
int buttonTotalWidth = 0;
int buttonDistancePixel = 5;
int startPositionX = 0;
double startingPoint = 0;
int i = 0;
for (i =0;i<buttonArr.GetLength(0); i++)
{
if (buttonArr[i].Visible == true)
{
buttonCount++;
buttonTotalWidth += buttonArr[i].Width;
buttonTotalWidth += buttonDistancePixel;
}
}
if (buttonTotalWidth > 0)
buttonTotalWidth -= buttonDistancePixel;
startingPoint = (formWidth / 2) - (buttonTotalWidth / 2);
startPositionX = Convert.ToInt32(Math.Round(startingPoint));
if (startPositionX > 0)
{
for (i = 0; i < buttonArr.Count(); i++)
{
if (buttonArr[i].Visible == true)
{
buttonArr[i].Left = startPositionX;
buttonArr[i].Top = startPositionY;
startPositionX += buttonArr[i].Width;
startPositionX += buttonDistancePixel;
}
}
}
}
示例2: IsWinner
//Check if the player has found all the nonmine fields
public void IsWinner(Button[,] buttons)
{
bool isBomb = true;
for (int row = 0; row < buttons.GetLength(0); row++)
{
for (int col = 0; col < buttons.GetLength(1); col++)
{
if (buttons[row, col].Enabled == true)
{
if (playBoardMatrix[row, col] == 0)
{
isBomb = false;
}
}
}
}
if (isBomb)
{
MessageBox.Show("You Won","WINNER");
FormLevel.ActiveForm.Close();
}
}
示例3: ClickBombs
//Find and click all mines
public void ClickBombs(Button[,] playboard, sbyte[,] fields)
{
for (int i = 0; i < playboard.GetLength(0); i++)
{
for (int j = 0; j < playboard.GetLength(1); j++)
{
if (fields[i, j] == 1)
{
playboard[i, j].BackgroundImageLayout = ImageLayout.Stretch;
playboard[i, j].BackgroundImage = Properties.Resources.bomb;
playboard[i, j].Enabled = false;
}
}
}
}
示例4: FormLevel_Load
// Generate the playboard of buttons and resize the form depending on level
private void FormLevel_Load(object sender, EventArgs e)
{
FormLvlSelection.ActiveForm.Hide();
if (rows == 30)
{
this.Size = new Size(25 * (rows + 3), 25 * (cols + 4));
}
else
{
this.Size = new Size(25 * (cols + 3), 25 * (rows + 4));
}
mines.Generate(numMines, rows, cols);
Button[,] fields = new Button[rows, cols];
int x = 25;
int y = 40;
for (int i = 0; i < fields.GetLength(0); i++)
{
for (int j = 0; j < fields.GetLength(1); j++)
{
//Set all the properties and events needed to the button
Button btn = new Button();
btn.BackColor = Color.White;
btn.Text = "";
btn.Location = new Point(x + (25 * i), y + (25 * j));
btn.Size = new Size(25, 25);
btn.Name = string.Format("btnR{0}C{1}", i, j);
btn.Click += (sender1, ex) =>
{
ButtonClickEvent(btn, fields);
};
btn.MouseDown += (sender2, ex2) =>
{
if (ex2.Button == MouseButtons.Right && btn.Text == "")
{
btn.Text = "B";
}
else if (ex2.Button == MouseButtons.Right && btn.Text == "B")
{
btn.Text = "";
}
};
fields[i, j] = btn;
this.Controls.Add(btn);
}
}
lblBombs.Text = string.Format("Bombs: {0}", numMines);
}
示例5: ClearField
//Click all fields around the clicked field
public void ClearField(Button clickedButton, Button[,] playBoard)
{
//Get coordinates from the name of the clicked field
int[] rowCol = clickedButton.Name.ToString().Split(new string[] { "btnR", "C" }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
int row = rowCol[0];
int col = rowCol[1];
if (row == 0)
{
if (col == 0)
{
playBoard[row, col + 1].PerformClick();
playBoard[row + 1, col].PerformClick();
playBoard[row + 1, col + 1].PerformClick();
}
else if (col == playBoard.GetLength(1) - 1)
{
playBoard[row + 1, col].PerformClick();
playBoard[row + 1, col - 1].PerformClick();
playBoard[row, col - 1].PerformClick();
}
else
{
playBoard[row, col - 1].PerformClick();
playBoard[row, col + 1].PerformClick();
playBoard[row + 1, col - 1].PerformClick();
playBoard[row + 1, col].PerformClick();
playBoard[row + 1, col + 1].PerformClick();
}
}
else if (row == playBoard.GetLength(0) - 1)
{
if (col == 0)
{
playBoard[row, col + 1].PerformClick();
playBoard[row - 1, col].PerformClick();
playBoard[row - 1, col + 1].PerformClick();
}
else if (col == playBoard.GetLength(1) - 1)
{
playBoard[row - 1, col].PerformClick();
playBoard[row - 1, col - 1].PerformClick();
playBoard[row, col - 1].PerformClick();
}
else
{
playBoard[row, col - 1].PerformClick();
playBoard[row, col + 1].PerformClick();
playBoard[row - 1, col - 1].PerformClick();
playBoard[row - 1, col].PerformClick();
playBoard[row - 1, col + 1].PerformClick();
}
}
else if (col == 0)
{
playBoard[row, col + 1].PerformClick();
playBoard[row - 1, col].PerformClick();
playBoard[row - 1, col + 1].PerformClick();
playBoard[row + 1, col].PerformClick();
playBoard[row + 1, col + 1].PerformClick();
}
else if (col == playBoard.GetLength(1) - 1)
{
playBoard[row, col - 1].PerformClick();
playBoard[row - 1, col].PerformClick();
playBoard[row - 1, col - 1].PerformClick();
playBoard[row + 1, col].PerformClick();
playBoard[row + 1, col - 1].PerformClick();
}
else
{
playBoard[row, col - 1].PerformClick();
playBoard[row, col + 1].PerformClick();
playBoard[row - 1, col - 1].PerformClick();
playBoard[row - 1, col].PerformClick();
playBoard[row - 1, col + 1].PerformClick();
playBoard[row + 1, col - 1].PerformClick();
playBoard[row + 1, col].PerformClick();
playBoard[row + 1, col + 1].PerformClick();
}
}