WinForm 窗体应用程序 (初步)之二
现在,我们来了解一些基本控件。控件是放置在工具箱里的,你可以在界面的左侧或者通过菜单栏的视图选项找到它。
(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 窗体应用程序 (初步)之二的更多相关文章
- C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB
C# winform 窗体应用程序之图片上传Oracle数据库保存字段BLOB 我用的数据库是Oracle,就目前来看,许多数据库现在都倾向于Oracle数据库,对ORACLE数据库基本的操作也是必须 ...
- winform窗体 小程序【线程】
线程是进程中执行运算的最小单位,也是执行处理机调度的基本单位.实际上线程是轻量级的进程.那么为什么要使用线程呢? (1)易于调度. (2)提高并发性.通过线程可方便有效地实现并发性.进程可创建多个线程 ...
- WinForm 窗体应用程序(初步)之一
学习制作一个WinForm程序,有两样东西是需要首先掌握的.第一部分,我们称之为属性面板.无论是窗体还是控件,都有着自己的属性面板.第二部分,则是我们称之为控件的东西. 我们先来讨论一下属性面板.新建 ...
- WinForm 窗体应用程序(初步)之三
进程: 进程,简单的说,就是让你的程序启动另一个程序. 1.Process.Start("calc");//启动计算器 弊端:只认识系统自带的程序,如果写错系统会崩溃. 2. // ...
- WinForm窗体更新程序
流程介绍: 打包参阅:WinForm程序打包说明 图一 图二 图三 实现步骤: 主程序 1.检测是否连上ftp服务器 1.1 连接不上,不检测. 1.2 连接上,如果有更新进程, ...
- 《winform窗体应用程序》----------简易记事本
首先先给大家发表几张图片,描述一下记事本程序要实现的功能以及界面设计. 以上这些就是简易记事本的的主界面设计. 下面我们来做一些简单的讲解: 1.使用MenuStrip控件来实现菜单栏的基本设计. 在 ...
- 设置WinForm窗体及程序图标
自己留着看,总是用的时候给忘记了,百度来百度去的麻烦. 设置 Ico 图标为 [资源文件] 项目名à右键à属性,在选项卡中选择"资源" 选择 "添加资源"à ...
- winform窗体 小程序【进程】
进程 一个应用程序就是一个进程,我的理解是,只要是打开应用程序,就会创建进程. 在.NET框架在using.System.Diagnostics名称空间中,有一个类Process,用来创建一个新的进程 ...
- winform窗体 小程序【登录窗体】【恶搞程序】
登录窗体 using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; ...
随机推荐
- TypeScript实例
interface Person { firstName: string, lastName: string } function greeter(person: Person) { return p ...
- 关于OpenVPN的入门使用
关于OpenVPN的入门使用 1.1源代码编译安装的初步了解 1.2 安装OpenVPN 1.3 生成证书.服务器端证书.客户端证书 1.4 关于server.ovpm & client.ov ...
- 【WP开发】正确理解页面缓存
注:本文内容面向Runtime App. 在新建项目后,细心观察,你会发现在App类中有以下代码: // TODO: 将此值更改为适合您的应用程序的缓存大小 rootFrame.CacheSize = ...
- 【Java基础】泛型
Num1:请不要在新代码中使用原生类型 泛型类和接口统称为泛型.每种泛型定义一组参数化的类型,构成格式是:类或接口名称,接着用<>把对应于泛型形式类型的参数的实际参数列表括起来.比如:Li ...
- Android图片加载库的理解
前言 这是“基础自测”系列的第三篇文章,以Android开发需要熟悉的20个技术点为切入点,本篇重点讲讲Android中的ImageLoader这个库的一些理解,在Android上最让人头疼是 ...
- 实例演示Android异步加载图片
本文给大家演示异步加载图片的分析过程.让大家了解异步加载图片的好处,以及如何更新UI.首先给出main.xml布局文件:简单来说就是 LinearLayout 布局,其下放了2个TextView和5个 ...
- 抓包分析SSL/TLS连接建立过程【总结】
1.前言 最近在倒腾SSL方面的项目,之前只是虽然对SSL了解过,但是不够深入,正好有机会,认真学习一下.开始了解SSL的是从https开始的,自从百度支持https以后,如今全站https的趋势越来 ...
- Spring Setter Injection and Constructor Injection
Setter Injection AppContext.xml <?xml version="1.0" encoding="UTF-8"?> < ...
- C#实现WinForm DataGridView控件支持叠加数据绑定
我们都知道WinForm DataGridView控件支持数据绑定,使用方法很简单,只需将DataSource属性指定到相应的数据源即可,但需注意数据源必须支持IListSource类型,这里说的是支 ...
- 图论 --- spfa + 链式向前星 (模板题) dlut 1218 : 奇奇与变形金刚
1218: 奇奇与变形金刚 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 130 Solved: 37[Submit][Status][Web Boa ...