现在的位置: 首页 > 综合 > 正文

C#学习之愚人节程序

2018年04月25日 ⁄ 综合 ⁄ 共 4179字 ⁄ 字号 评论关闭

愚人节没被表白,想想在如此佳节,居然如此冷清,于是用最近学的C#写了下面的程序,可以整蛊一下小白。。。。。

其实就是无论如何你也点不到关闭,因为按钮会跑。。而且右上角的关闭也被做了手脚。。要怎样才能关闭程序?。。大家安装一下。。。。微笑成品在这点击打开链接

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
       
        Point button_p;
        bool flag = false;
        Timer count = new Timer();
        public Form1()
        { 
            
            InitializeComponent();
            count.Interval = 100000;
            //count.Interval = 4000;
            count.Start();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult dr = MessageBox.Show("你真的要关吗 (>﹏<)", "提示",
                MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (dr == DialogResult.Yes)
            {
                if (MessageBox.Show("不要关好不  ╮(╯﹏╰)╭", "提示",
                MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    if (MessageBox.Show("就是不关,咬我呀!(┬_┬)", "提示",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        e.Cancel = true;
                    }
                    else e.Cancel = true;
                }
                else e.Cancel = true;
            }
            if (dr == DialogResult.No)
            {
                e.Cancel = true;

            }
        }

        void count_Tick(object sender, EventArgs e)
        {
            //count.Interval = 5000;
            // count.Start();
            count.Stop();
            MessageBox.Show("4.1快乐 O(∩_∩)O  ,关闭方法有两个! \n\n1:打开资源管理器,关闭程序 \n2:左手按 Ctrl ,右手点关闭");
            
        }

        private void buttonMove_MouseEnter(object sender, EventArgs e)
        {
            //buttonMove.Left += 50;
            //if(this.PointToClient(Control.MousePosition).X <= (buttonMove.Left +panel1.Left))
            //{
            //    buttonMove.Left += 50;
            //}
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)//what is the difference between press and down
        {
            //if(e.KeyValue==32)
            //{
            //    Application.Exit();
            //}
            //Application.Exit();
        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //if (e.KeyChar == 'p')
            //{
            //    Application.Exit();
            //}
            //Application.Exit();
        }

        private void buttonMove_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')
            {
                //Application.Exit();//此时不能使用application,必须强制退出
                //Environment.Exit(0);
            }
        }

        private void panel1_MouseEnter(object sender, EventArgs e)
        {
            //panel1.Left += 50;
            ////textBox1.Text = Convert.ToString(this.PointToClient(Control.MousePosition).X) + "   " + Convert.ToString(buttonMove.Left);
            //if (this.PointToClient(Control.MousePosition).X < panel1.Left && 
            //    this.PointToClient(Control.MousePosition).Y<panel1.Bottom)
            //{
            //    panel1.Left -= 50;
            //    panel1.Top -= 50;
            //}
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            //panel1.Left += 20;
            //textBox1.Text = Convert.ToString(this.PointToClient(Control.MousePosition).X) + "   " + Convert.ToString(panel1.Left);
            // 1|2
            // 4|3
            //
            if (flag == false)
            {
                if (this.PointToClient(Control.MousePosition).X - 20 < panel1.Left &&
                    this.PointToClient(Control.MousePosition).Y - 20 < panel1.Top)
                {
                    panel1.Left += 20;
                    panel1.Top += 20;
                    if (panel1.Right > this.ClientRectangle.Width)
                    {
                        panel1.Left = 20;
                    }
                    if (panel1.Bottom > this.ClientRectangle.Height)
                    {
                        panel1.Top = 20;
                    }
                   // textBox1.Text = "1";
                    buttonMove.Text = "点我啊!";
                }
                //====================
                else if (this.PointToClient(Control.MousePosition).X + 20 > panel1.Right &&
                this.PointToClient(Control.MousePosition).Y + 20 > panel1.Bottom)
                {
                    panel1.Left -= 20;
                    panel1.Top -= 50;
                    if (panel1.Left < 0)
                    {
                        panel1.Left = this.ClientRectangle.Width - 100;
                    }
                    if (panel1.Top < 0)
                    {
                        panel1.Top = this.ClientRectangle.Height - 100;
                    }
                   // textBox1.Text = "3";
                    buttonMove.Text = "╮(╯▽╰)╭";

                }
                //====================
                else if (this.PointToClient(Control.MousePosition).X + 20 > panel1.Right ||
                this.PointToClient(Control.MousePosition).Y - 20 < panel1.Top)
                {
                    panel1.Left -= 20;
                    panel1.Top += 20;
                    if (panel1.Left < 0)
                    {
                        panel1.Left = this.ClientRectangle.Width - 100;
                    }
                    if (panel1.Bottom > this.ClientRectangle.Height)
                    {
                        panel1.Top = 20;
                    }
                   // textBox1.Text = "2";
                    buttonMove.Text = "点击可关闭";
                }
                //====================
                else if (this.PointToClient(Control.MousePosition).X - 20 < panel1.Left ||
                this.PointToClient(Control.MousePosition).Y + 20 > panel1.Bottom)
                {
                    panel1.Left += 20;
                    panel1.Top -= 50;
                    if (panel1.Right > this.ClientRectangle.Width)
                    {
                        panel1.Left = 20;
                    }
                    if (panel1.Top < 0)
                    {
                        panel1.Top = this.ClientRectangle.Height - 100;
                    }
                    //textBox1.Text = "4";
                    buttonMove.Text = "o(╯□╰)o";
                }
            }
        }

        private void buttonMove_KeyDown(object sender, KeyEventArgs e)
        {
           if(e.Control)
           {
               flag = true;
           }
        }

        private void buttonMove_Click(object sender, EventArgs e)
        {
            if(flag==true)
            {
                Environment.Exit(0);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("请点击关闭");
        }

        private void buttonMove_MouseUp(object sender, MouseEventArgs e)
        {
               // flag = false;
        }

        private void buttonMove_KeyUp(object sender, KeyEventArgs e)
        {     
               flag = false;
        }
    }
}

小小的练习程序,在愚人节聊以自慰。。。。。。。

 

抱歉!评论已关闭.