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

(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. ES2005 js =>

    ES2005 js => 不会写js Learn ES2015

  2. vm中centos7配置静态ip访问外网

    我使用的是桥接方式,具体步骤如下   1.设置虚拟机网络: 编辑>虚拟网络编辑器   2.设置vm中操作系统的网络设置   3.进入centos7中后修改网络配置:     另附我的宿主机网络配 ...

  3. 【WP开发】实现“摇一摇”功能

    尽管我的微信是每八个月登录一次,但我相信各位玩得比我多.微信有一个“摇一摇”功能,这个功能其实是利用了加速度传感器来实现的,这个传感器,我估计再低端的手机都会有的,这是严重基本的传感器. 重力加速度既 ...

  4. java集合框架之Set

    Set集合 元素不可以重复,是无序. 方法与list相同 HashSet:不保证set的迭代顺序,不同步,内部数据结构是哈希表 如果存自定义对象则需要覆盖equals和hashCode方法 先比较ha ...

  5. 如何用Python输出PPT中的文字信息

    在这里,会用到win32com模块 模块下载地址:http://sourceforge.net/projects/pywin32/files/pywin32/ 代码如下: import win32co ...

  6. Redis在win7上的可视化应用

    Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  7. MySQL的学习--join和union的用法

    感觉工作之后一直在用框架,数据库的一些基本的东西都忘记了,这次借着这个系列的博客回顾一下旧知识,学一点新知识. 今天就先从join和union开始. join 是两张表做交连后里面条件相同的部分记录产 ...

  8. VS2013正则表达式应用示例

    VS2013正则表达式语法 在查找替换对话框中查看 VS2013语法可在查找替换对话框中查看,具体过程如下: 通过编辑->查找和替换->在文件中替换或者相应快捷键(Ctrl+Shift+H ...

  9. CentOS 7 关闭防火墙和SELinux

    [修改机器名] # vi /etc/hostname [关SELinux] # vi /etc/selinux/config设置SELINUX=disabled [关防火墙] # systemctl ...

  10. [转载]在SQL Server 中,如何实现DBF文件和SQL Server表之间的导入或者导出?

    原来使用SQL Server 2000数据库,通过DTS工具很方便地在SQL Server和DBF文件之间进行数据的导入和导出,现在安装了SQL Server2005之后,发现其提供的“SQL Ser ...