利用C#中WinForm设计一个小游戏:DoYouLoveMe???

发布于:2024-05-24 ⋅ 阅读:(166) ⋅ 点赞:(0)

目录

一、WinForm

二、功能实现

三、代码部分

 


一、WinForm

Windows 窗体是用于生成 Windows 桌面应用的 UI 框架。 它提供了一种基于 Visual Studio 中提供的可视化设计器创建桌面应用的高效方法。 利用视觉对象控件的拖放放置等功能,可以轻松生成桌面应用。

使用 Windows 窗体,可以开发包含丰富图形的应用,这些应用易于部署和更新,并且在脱机状态下或连接到 Internet 时都可正常工作。 Windows 窗体应用可以访问运行应用的计算机的本地硬件和文件系统。

二、功能实现

说明:只有一句话和两个按钮,点击“爱”的按钮,弹出提示“我也爱你”,点击“不爱”按钮,不爱按钮自动在form窗体中随机新的位置,如果缩小窗体点击到“不爱”按钮,弹出提示“被你这个老六按到了”,结束。页面设计

三、代码部分

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 DoYouLoveMe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("我也爱你呦!!!");
            this.Close();
        }

        private void button2_MouseEnter(object sender, EventArgs e)
        {
            int x = this.ClientSize.Width - button2.Width;
            int y = this.ClientSize.Height - button2.Height;
            Random r = new Random();
            button2.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("被你这个老六点到了");
            this.Close();
        }
    }
}

 


网站公告

今日签到

点亮在社区的每一天
去签到