我想用c#做五子棋界面,将棋盘的图片作为主窗体的背景。现在想每单击一个交叉点,就能将棋子的图片放到相应位置。棋子的图片在imagelist控件里。
目前,我已经实现了、每单击一个位置,就能把那个位置的棋盘坐标找到。
怎么实现点击一个位置,把棋子的图片放到目标位置呢?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 五子棋
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Point mm(int x, int y)
{
return new Point((x / 31 + 1 / 31), (y / 31 + 1 / 31));
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
switch (e.Button)
{
case MouseButtons.Left:
label1.Text = (mm(e.X, e.Y).X + 1).ToString() + "," + (mm(e.X, e.Y).Y + 1).ToString();
System.Drawing.Graphics g = this.CreateGraphics();
imageList1.Draw(g, e.X, e.Y, 20, 20, 0);
break;
}
}
}
}
我那么写怎么没反应呢