大家好,这次我要为大家带来的是一个用C#写的WinForm游戏,名字叫做拼图游戏。拼图游戏想必大家肯定玩过,玩法我就不赘述了。
首先向大家展示一下运行效果图吧:
1:写一个WinForm游戏首先要干嘛呢?
当能是打开vs2010,创建一个Window应用程序了。那么我们就创建一个应用程序,并命名为: LilacFlower。对于一个窗体应用程序,vs2010在图形界面对控件的布局以及属性事件的设置可以说是当今世界上最好的软件了。那么我们从工具箱里面拖动控件放到窗体界面上,效果图如下:
具体参照Form1.Designer.cs文件:
namespace LilacFlower
{
partial class Form1
{
/// <summary>
///
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
///
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows フォーム デザイナーで生成されたコード
/// <summary>
///
///
/// </summary>
private void InitializeComponent()
{
this.mainPanel = new System.Windows.Forms.Panel();
this.modePicture = new System.Windows.Forms.PictureBox();
this.difficultySelection = new System.Windows.Forms.ComboBox();
this.txtLabel = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.startbtn = new System.Windows.Forms.Button();
this.addPicturebtn = new System.Windows.Forms.Button();
this.pictureShowListBox = new System.Windows.Forms.ListBox();
((System.ComponentModel.ISupportInitialize)(this.modePicture)).BeginInit();
this.SuspendLayout();
//
// mainPanel
//
this.mainPanel.Location = new System.Drawing.Point(151, 14);
this.mainPanel.Name = "mainPanel";
this.mainPanel.Size = new System.Drawing.Size(500, 500);
this.mainPanel.TabIndex = 0;
//
// modePicture
//
this.modePicture.Location = new System.Drawing.Point(12, 12);
this.modePicture.Name = "modePicture";
this.modePicture.Size = new System.Drawing.Size(120, 120);
this.modePicture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.modePicture.TabIndex = 0;
this.modePicture.TabStop = false;
this.modePicture.Click += new System.EventHandler(this.modePicture_Click);
//
// difficultySelection
//
this.difficultySelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.difficultySelection.FormattingEnabled = true;
this.difficultySelection.Items.AddRange(new object[] {
"简单(3*3)",
"中等(5*5)",
"困难(7*7)"});
this.difficultySelection.Location = new System.Drawing.Point(45, 160);
this.difficultySelection.Name = "difficultySelection";
this.difficultySelection.Size = new System.Drawing.Size(88, 20);
this.difficultySelection.TabIndex = 0;
//
// txtLabel
//
this.txtLabel.AutoS