我在做五子棋程序的时候遇到这个问题:
我在FORM1上放了PictureBox然后在PictureBox上加载棋盘图片 然后用程序实现下棋
我是这样画棋子的:
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
g.DrawImage(this.imageList1.Images[chess.ChessColor - 1],chess.Pos.X,chess.Pos.Y,35,35);
this.pictureBox1.Refresh();
我想实现悔棋 就必须把前一步的棋子擦除 可是这样画上去的图片怎样才能擦除呢?
我尝试了很多方法都失败了 大家指点我一下 非常感谢:)
我在FORM1上放了PictureBox然后在PictureBox上加载棋盘图片 然后用程序实现下棋
我是这样画棋子的:
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
g.DrawImage(this.imageList1.Images[chess.ChessColor - 1],chess.Pos.X,chess.Pos.Y,35,35);
this.pictureBox1.Refresh();
我想实现悔棋 就必须把前一步的棋子擦除 可是这样画上去的图片怎样才能擦除呢?
我尝试了很多方法都失败了 大家指点我一下 非常感谢:)
解决方案 »
- 很急 关于C/S 中treeview图标动态绑定不显示的问题
- web 中 时间.ToString()的参数问题
- 急!如何将两个线程装到一个静态类里,然后就在一个程序里用!
- 如何做一个sql express的安装程序?
- 我想生成树状目录,可以让用户修改,请问哪们高手有代码?
- C#可以实现在IE中直接通过Socket而不使用AcitveX控件与Web服务器进行TCP连接通信吗?
- .NET CF下控件新增事件的问题?
- 求肋:基于WebService的数据库同步编程问题
- Form设置Topmost属性, 执行显示桌面后, 可以被其它程序遮挡。怎么判断我原来的窗体还在整个Windows的最上面?
- 小问题:C#如何实现VB中类似Execute或是Eval的功能
- 在C#中如何使Label背景透明?
- 在windows应用程序里面如何使用cache?
这样可以专注于旗游戏程序逻辑,不考虑画图等方面的情况
我也确实是用ImageList放了一黑一白存储
后来我用每个棋子都用pictureBox来显示 但是棋子是圆的 PictureBox确实方的 即使我的图片背景色为透明 显示棋子的时候也会留有边角的白色部分 这是我否定这个方法的原因
我原来是用pictureBox.CreateGraphics()方法配合ImageList.Draw()方法画棋子的 下棋,悔棋都实现的很成功 但是有个问题 就是当整个程序窗口最小化后再还原为正常窗口后 棋盘上的所有棋子就被"洗"掉了!所以我才采用上面"洗"不掉棋子的方法
哎 现在悔棋想"洗"掉的时候又无能为力了...
Graphics g = Graphics.FromImage(this.pictureBox1.Image); g.DrawImage(“悔棋前棋盘状态”);this.pictureBox1.Refresh();
上面两位的方法我都想过了
但是具体到怎么保存要画棋子的地方还是重建整个棋盘 我都不知道有什么办法能够实现
对于保存画棋子前的地方的方案 我是根本不知道有什么方法能保存某一指定的窗体图案
而对于后者 重建整个棋盘的方案 我想到用栈mystack.Push(pictureBox1.Image);的方法在每次下其都保存一次悔棋前的棋盘 但是当我mystack.Pop()出保存的棋盘再拿它给pictureBox1.Image赋值的时候 却还原不回悔棋前的图案!
Graphics g = Graphics.FromImage(this.pictureBox1.Image); \
g.DrawImage(xx);
为什么还要给pictureBox1.Image属性赋值呢??
如果盘面和棋子都是用绘图的方法绘出来的PictureBox的绘图表面绘制出来的话pictureBox1.Image的属性可以一直都为空啊!或者用棋盘图片作这个属性,每次绘图(下子也好,悔棋也好)都只是重绘全部的棋子也可以阿
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows フォーム デザイナで生成されたコード private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(544, 408);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// button1
//
this.button1.Location = new System.Drawing.Point(168, 424);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Clean";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(544, 453);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion [STAThread]
static void Main()
{
Application.Run(new Form1());
} private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Image img=Image.FromFile("Black.bmp");
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
g.DrawImage(img,e.X,e.Y,img.Width,img.Height);
this.pictureBox1.Refresh();
} private void button1_Click(object sender, System.EventArgs e)
{
Image img=Image.FromFile("Back.bmp");
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
g.DrawImage(img,0,0,img.Width,img.Height);
this.pictureBox1.Refresh();
} }
}
apollp(形影相吊) 的方法倒可以尝试一下:)
在一个数组中(或是别的什么),把所下的子记录下来,顺序也要记下.
在OnPain事件中,根据数组中的记录情况重建棋盘,这种思想我在写
俄罗斯方块游戏时,用过,可行,只是屏幕有闪烁的现像,估计用DX来
写的话,会好一些.