制作方块出了问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace tetris
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool[,] struArr = new bool[5, 5];
Color blockColor = Color.Red;
private void label1_Paint(object sender, PaintEventArgs e)
{
Graphics gp = e.Graphics;
Pen p = new Pen(Color.White);
for (int i = 0; i < 155; i = i + 31)//0 not 1
{
gp.DrawLine(p, 1, i, 155, i);
}
for (int i = 0; i < 155; i = i + 31)
{
gp.DrawLine(p, i, 1, i, 155);
}
}
private void label1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
int xPos, yPos;
xPos = e.X / 31;
yPos = e.Y / 31;
struArr[xPos, yPos] = !struArr[xPos, yPos];
bool b = struArr[xPos, yPos];
Graphics gp = label1.CreateGraphics();
SolidBrush s = new SolidBrush(b ? blockColor : Color.Black);
gp.FillRectangle(s, 31 * xPos + 1, 31 * yPos + 1, 30, 30);
gp.Dispose();
}
}
} 当你移动鼠标时
回自动画黑线
不知哪儿错了
如附件所示
QQ截图未命名.rar
(642 Bytes)