いくつかのクイックコンテキスト:このプロジェクトでは、Visual C#Windowsフォームプロジェクトを使用してMinesweeperを再作成しています。Windowsフォームボタンのアクションを右クリック
私はCell(Control.Buttonを継承しています)の配列を使用しています。
余分なクレジットとして、私はあなたがゲームのクラスバージョンでできるように、セルにフラグを立てることができるようにします。しかし、私は右クリックして作業することはできません。
解決策を見つけようとすると、EventArgをMouseEventArgとして型キャストする必要があることがわかりましたが、右クリックをしてもクリックイベントが発生しなくなるため、問題は解決しませんでした。私はからtype-casting the event argumentsをつかんだところ
namespace Project_5___Minesweeper_GUI
{
public partial class Form1 : Form
{
public class Cell : Button { /*Custom Cell-Stuff Goes Here*/ }
Cell[,] board = new Cell[AXIS_LENGTH, AXIS_LENGTH]; //Axis Length is just the dimensions of the board (I use 10x10).
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < AXIS_LENGTH; i++)
{
for (int j = 0; j < AXIS_LENGTH; j++)
{
board[i, j] = new Cell();
//Set position and size
board[i, j].MouseClick += button_arrayClick; //button_arrayClick() is never called by a right-click. Code for it is below. I suspect this line of code has to do with right-clicks not class button_arrayClick().
groupBox1.Controls.Add(board[i, j]); //I'm containing the array of Cells inside of a groupbox.
}
}
}
private void button_arrayClick(object sender, EventArgs e) //Is prepared for handling a right-click, but never receives them.
{
Cell temp = (Cell)sender;
MouseEventArgs me = (MouseEventArgs)e;
if (me.Button == MouseButtons.Left)
{
//Stuff that happens on left-click
} else {
//Stuff that happens on right-click
}
}
}
}
これは、次のとおりです。
はここにいくつかの言い換えのコードです。
感謝を聞いてくれ!このソリューションは機能し、私は今、私のセルのために機能する右クリックを持っています。 –