现在,我们来了解一些基本控件。控件是放置在工具箱里的,你可以在界面的左侧或者通过菜单栏的视图选项找到它。

(1)Label 控件 这是一个用于放置文字的控件,因为你不能在窗体上直接输入文字。

(2)TextBox 文本框

(3)Button 按钮

(4)CheckBox 复选框

(5)Panel  分组容器,类似于HTML中的div

(6)PictureBox 图片框

(7)WebBrowser 它可以允许用户在窗体内浏览网页,可用于制作浏览器

下面附上笔者自制的一个拼图游戏及代码文件:

 using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ImgList = null;
}
#region 定义字段
List<Image> _imgList;
/// <summary>
/// 定义属性
/// </summary>
public List<Image> ImgList
{
get { return _imgList; }
set
{
_imgList = new List<Image>();
_imgList.Add(pictureBox1.BackgroundImage);
_imgList.Add(pictureBox2.BackgroundImage);
_imgList.Add(pictureBox3.BackgroundImage);
_imgList.Add(pictureBox4.BackgroundImage);
_imgList.Add(pictureBox5.BackgroundImage);
_imgList.Add(pictureBox6.BackgroundImage);
}
}
#endregion
#region 开始按钮
private void button1_Click(object sender, EventArgs e)
{
//随机6个不同的数
Random rd = new Random();
int[] x = new int[];
for (int i = ; i < ; i++)
{
x[i] = rd.Next(, );
for (int j = ; j < i; j++)
{
if (x[i] == x[j])
{
i--;
break;
}
}
}
//重新设置图像
pictureBox1.BackgroundImage = ImgList[x[]];
pictureBox2.BackgroundImage = ImgList[x[]];
pictureBox3.BackgroundImage = ImgList[x[]];
pictureBox4.BackgroundImage = ImgList[x[]];
pictureBox5.BackgroundImage = ImgList[x[]];
pictureBox6.BackgroundImage = ImgList[x[]];
//倒计时开始,并允许玩家操作
time = ;
label2.Text="";
timer1.Start();
pictureBox1.Enabled = true;
pictureBox2.Enabled = true;
pictureBox3.Enabled = true;
pictureBox4.Enabled = true;
pictureBox5.Enabled = true;
pictureBox6.Enabled = true;
}
#endregion
#region 玩家操作
//定义匹配变量
int match = ;
//存储上一张图片
PictureBox lpb = new PictureBox();
//响应用户操作
private void pictureBox1_Click(object sender, EventArgs e)
{
PictureBox pb = sender as PictureBox;
//截取Name的最后一位作为唯一标识
int n = int.Parse(pb.Name.Substring(, ));
//判断是否已经正确归位,如果没有正确归位
if (pb.BackgroundImage != ImgList[n - ])
{
//重置参数
if (match == )
{
match = ;
}
//交换背景图片
if (match == )
{
Image img = pb.BackgroundImage;
pb.BackgroundImage = lpb.BackgroundImage;
lpb.BackgroundImage = img;
//判断是否全部归位
if (pictureBox1.BackgroundImage == ImgList[] && pictureBox2.BackgroundImage == ImgList[] && pictureBox3.BackgroundImage == ImgList[] && pictureBox4.BackgroundImage == ImgList[] && pictureBox5.BackgroundImage == ImgList[] && pictureBox6.BackgroundImage == ImgList[])
{
timer1.Stop();
MessageBox.Show("恭喜您,顺利过关!");
}
}
lpb = pb;
match++;
}
}
#endregion
#region 计时功能
int time = ;
private void timer1_Tick(object sender, EventArgs e)
{
if (time > )
{
time--;
label2.Text = time.ToString();
}
else
{
//停止计时,并禁止玩家操作
timer1.Stop();
pictureBox1.Enabled = false;
pictureBox2.Enabled = false;
pictureBox3.Enabled = false;
pictureBox4.Enabled = false;
pictureBox5.Enabled = false;
pictureBox6.Enabled = false;
MessageBox.Show("很遗憾,游戏失败!");
}
}
#endregion }
}

WinForm 窗体应用程序 (初步)之二的更多相关文章

  1. C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB

    C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB 我用的数据库是Oracle,就目前来看,许多数据库现在都倾向于Oracle数据库,对ORACLE数据库基本的操作也是必须 ...

  2. winform窗体 小程序【线程】

    线程是进程中执行运算的最小单位,也是执行处理机调度的基本单位.实际上线程是轻量级的进程.那么为什么要使用线程呢? (1)易于调度. (2)提高并发性.通过线程可方便有效地实现并发性.进程可创建多个线程 ...

  3. WinForm 窗体应用程序(初步)之一

    学习制作一个WinForm程序,有两样东西是需要首先掌握的.第一部分,我们称之为属性面板.无论是窗体还是控件,都有着自己的属性面板.第二部分,则是我们称之为控件的东西. 我们先来讨论一下属性面板.新建 ...

  4. WinForm 窗体应用程序(初步)之三

    进程: 进程,简单的说,就是让你的程序启动另一个程序. 1.Process.Start("calc");//启动计算器 弊端:只认识系统自带的程序,如果写错系统会崩溃. 2. // ...

  5. WinForm窗体更新程序

    流程介绍: 打包参阅:WinForm程序打包说明    图一    图二    图三   实现步骤: 主程序 1.检测是否连上ftp服务器 1.1 连接不上,不检测. 1.2 连接上,如果有更新进程, ...

  6. 《winform窗体应用程序》----------简易记事本

    首先先给大家发表几张图片,描述一下记事本程序要实现的功能以及界面设计. 以上这些就是简易记事本的的主界面设计. 下面我们来做一些简单的讲解: 1.使用MenuStrip控件来实现菜单栏的基本设计. 在 ...

  7. 设置WinForm窗体及程序图标

    自己留着看,总是用的时候给忘记了,百度来百度去的麻烦. 设置 Ico 图标为 [资源文件] 项目名à右键à属性,在选项卡中选择"资源"   选择 "添加资源"à ...

  8. winform窗体 小程序【进程】

    进程 一个应用程序就是一个进程,我的理解是,只要是打开应用程序,就会创建进程. 在.NET框架在using.System.Diagnostics名称空间中,有一个类Process,用来创建一个新的进程 ...

  9. winform窗体 小程序【登录窗体】【恶搞程序】

    登录窗体 using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; ...

随机推荐

  1. WPF Bitmap转Imagesource

    var imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),IntPtr ...

  2. 如何用Python实现目录遍历

    1. 基本实现 [root@localhost ~]# cat dirfile.py import os path='/tmp' for dirpath,dirnames,filenames in o ...

  3. prototype.js 和 jQuery.js中 ajax 的使用

    这次还是prototype.js 和 jQuery.js冲突的问题,前面说到过解决办法http://www.cnblogs.com/Joanna-Yan/p/4836252.html,以及上网说的大部 ...

  4. KafkaConfig介绍

    public class KafkaConfig implements Serializable { /** 一个借口,实现类有ZkHosts,和StatisHosts **/ public fina ...

  5. Windows Azure Cloud Service (38) 微软IaaS与PaaS比较

    <Windows Azure Platform 系列文章目录> 最近一直想总结Azure IaaS和PaaS的区别与比较,写个博文详细说明一下.建议读者在阅读之前,先熟悉微软PaaS和Ia ...

  6. Elasticsearch嵌套聚合

    Elasticserch在新版本中支持聚合操作,而聚合操作也可以嵌套使用,方法如下: curl -XGET 10.4.44.19:9200/test/test/_search?pretty -d ' ...

  7. 索引深入浅出(5/10):非聚集索引的B树结构在堆表

    在“索引深入浅出:非聚集索引的B树结构在聚集表”里,我们讨论了在聚集表上的非聚集索引,这篇文章我们讨论下在堆表上的非聚集索引. 非聚集索引可以在聚集表或堆表上创建.当我们在聚集表上创建非聚集索引时,聚 ...

  8. 分享在winform下实现左右布局多窗口界面

    在web页面上我们可以通过frameset,iframe嵌套框架很容易实现各种导航+内容的布局界面,而在winform.WPF中实现其实也很容易,我这里就分享一个:在winform下实现左右布局多窗口 ...

  9. linux专题三之如何悄悄破解root密码(以redhat7.2x64为例)

    root用户在linux系统中拥有至高无上的权限.掌握了root密码,差不对可以对linux系统随心所欲了,当然了,root用户也不是权限最高的用户. 但是掌握了root密码,基本上够我们用了.本文将 ...

  10. 大话immutable.js

    为啥要用immutable.js呢.毫不夸张的说.有了immutable.js(当然也有其他实现库)..才能将react的性能发挥到极致!要是各位看官用过一段时间的react,而没有用immutabl ...