欢迎来到 IT实训基地-南通科迅教育
咨询电话:0513-81107100
WinForm做的整人小游戏
2018/4/8
科迅教育
1116
南通Java培训班有用吗

今天来做一个整人的小游戏?先放图


图片1.jpg 


图片2.jpg


图片3.jpg


不管你点个按钮都会显示你是学渣

设计代码放出

namespace _22net

{

    partial class Form1

    {

        /// <summary>

        /// 必需的设计器变量。

        /// </summary>

        private System.ComponentModel.IContainer components = null;

 

        /// <summary>

        /// 清理所有正在使用的资源。

        /// </summary>

        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false</param>

        protected override void Dispose(bool disposing)

        {

            if (disposing && (components != null))

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }

 

        #region Windows 窗体设计器生成的代码

 

        /// <summary>

        /// 设计器支持所需的方法 - 不要

        /// 使用代码编辑器修改此方法的内容。

        /// </summary>

        private void InitializeComponent()

        {

            this.components = new System.ComponentModel.Container();

            this.button1 = new System.Windows.Forms.Button();

            this.button2 = new System.Windows.Forms.Button();

            this.timer1 = new System.Windows.Forms.Timer(this.components);

            this.label1 = new System.Windows.Forms.Label();

            this.SuspendLayout();

            //

            // button1

            //

            this.button1.Location = new System.Drawing.Point(69, 222);

            this.button1.Name = "button1";

            this.button1.Size = new System.Drawing.Size(75, 23);

            this.button1.TabIndex = 0;

            this.button1.Text = "";

            this.button1.UseVisualStyleBackColor = true;

            this.button1.Click += new System.EventHandler(this.button1_Click);

            this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);

            //

            // button2

            //

            this.button2.Location = new System.Drawing.Point(184, 222);

            this.button2.Name = "button2";

            this.button2.Size = new System.Drawing.Size(75, 23);

            this.button2.TabIndex = 1;

            this.button2.Text = "不是";

            this.button2.UseVisualStyleBackColor = true;

            this.button2.Click += new System.EventHandler(this.button2_Click);

            this.button2.KeyUp += new System.Windows.Forms.KeyEventHandler(this.button2_KeyUp);

            this.button2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button2_MouseMove);

            this.button2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.button2_MouseUp);

            //

            // timer1

            //

            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

            //

            // label1

            //

            this.label1.AutoSize = true;

            this.label1.Location = new System.Drawing.Point(69, 73);

            this.label1.Name = "label1";

            this.label1.Size = new System.Drawing.Size(101, 12);

            this.label1.TabIndex = 2;

            this.label1.Text = "你是学渣吗???";

            //

            // Form1

            //

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = new System.Drawing.Size(456, 286);

            this.Controls.Add(this.label1);

            this.Controls.Add(this.button2);

            this.Controls.Add(this.button1);

            this.Name = "Form1";

            this.Text = "Form1";

            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);

            this.Load += new System.EventHandler(this.Form1_Load);

            this.ResumeLayout(false);

            this.PerformLayout();

 

        }

 

        #endregion

 

        private System.Windows.Forms.Button button1;

        private System.Windows.Forms.Button button2;

        private System.Windows.Forms.Timer timer1;

        private System.Windows.Forms.Label label1;

    }

}

 

事件代码放出

using System;

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 _22net

{

    public partial class Form1 : Form

    {

        Boolean flag = true;

        int time = 0;  

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

 

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            MessageBox.Show("我就知道你会选是的");

        }

 

        private void button2_KeyUp(object sender, KeyEventArgs e)

        {

            button2.Location = new System.Drawing.Point(2, 34);

        }

 

        private void button2_MouseUp(object sender, MouseEventArgs e)

        {

            button2.Location = new System.Drawing.Point(2, 34);

        }

 

        private void button2_MouseMove(object sender, MouseEventArgs e)

        {

            if (time <= 1)

                run();

            else

            {

 

                button1.Text = "不是";

                button2.Text = "";

            }

 

        }

        private void run()

        {

            timer1.Interval = 7;

            timer1.Start();

        }

 

        private void timer1_Tick(object sender, EventArgs e)

        {

            if (button2.Location.Y >= 50 && flag)

            {

                button2.Location = new System.Drawing.Point(button2.Location.X, button2.Location.Y - 1);

            }

            else

            {

                flag = false;

                button2.Location = new System.Drawing.Point(button2.Location.X, button2.Location.Y + 1);

            }

            if (button2.Location.Y >= button1.Location.Y || button2.Location.Y < 50)

            {

                time++;

                flag = true;

                timer1.Stop();

            }

 

        }

 

        private void button1_MouseMove(object sender, MouseEventArgs e)

        {

 

            button2.Text = "不是";

            button1.Text = "";

        }

 

 

        private void button2_Click(object sender, EventArgs e)

        {

            MessageBox.Show("我就知道你会选是的");

        }

 

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)

        {

            MessageBox.Show("关了窗口也改变不了你是学渣的事实");

        }

 

        

    }  

}

用来整人开玩笑还是比较有意思的。这期就到这里下期见!


77
关闭
先学习,后交费申请表
每期5位名额
在线咨询
免费电话
QQ联系
先学习,后交费
TOP
您好,您想咨询哪门课程呢?
关于我们
机构简介
官方资讯
地理位置
联系我们
0513-91107100
周一至周六     8:30-21:00
微信扫我送教程
手机端访问
南通科迅教育信息咨询有限公司     苏ICP备15009282号     联系地址:江苏省南通市人民中路23-6号新亚大厦三楼             法律顾问:江苏瑞慈律师事务所     Copyright 2008-