『7x24小时有问必答』
使用百度最新接入DeepSeek功能;写C# WinForm抽奖程序测试,真的不用写一行代码,就能实现;
一、效果展示
二、请帮我用C#写一个WinForm抽奖程序
代码加入到VS2022
三、DeepSeek代码
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace LotteryApplication
{
    public partial class MainForm : Form
    {
        private readonly List<string> participants = new List<string>
        {
            "张三""李四""王五""赵六""陈七",
            "林八""黄九""周十""吴十一""郑十二"
        };

        private readonly Random random = new Random();
        private bool isDrawing = false;

        public MainForm()
        {
            InitializeComponent();
            InitializeUI();
        }

        private void InitializeUI()
        {
            // 窗体设置
            this.Text = "电子抽奖系统";
            this.Size = new Size(600, 400);
            this.BackColor = Color.WhiteSmoke;

            // 抽奖显示标签
            var lblResult = new Label
            {
                Font = new Font("微软雅黑", 24, FontStyle.Bold),
                ForeColor = Color.DarkSlateBlue,
                Size = new Size(500, 100),
                Location = new Point(50, 50),
                TextAlign = ContentAlignment.MiddleCenter
            };

            // 控制按钮
            var btnStart = new Button
            {
                Text = "开始抽奖",
                Font = new Font("微软雅黑", 12),
                Size = new Size(120, 40),
                Location = new Point(150, 200),
                BackColor = Color.LimeGreen
            };

            var btnStop = new Button
            {
                Text = "停止",
                Font = new Font("微软雅黑", 12),
                Size = new Size(120, 40),
                Location = new Point(330, 200),
                BackColor = Color.OrangeRed,
                Enabled = false
            };

            // 定时器设置
            var timer = new Timer { Interval = 50 };

            // 事件绑定
            btnStart.Click += (s, e) =>
            {
                isDrawing = true;
                btnStart.Enabled = false;
                btnStop.Enabled = true;
                timer.Start();
            };

            btnStop.Click += (s, e) =>
            {
                isDrawing = false;
                btnStart.Enabled = true;
                btnStop.Enabled = false;
                timer.Stop();
                lblResult.ForeColor = Color.DarkRed;
            };

            timer.Tick += (s, e) =>
            {
                if (isDrawing)
                {
                    int index = random.Next(participants.Count);
                    lblResult.Text = participants[index];
                }
            };

            // 添加控件
            this.Controls.Add(lblResult);
            this.Controls.Add(btnStart);
            this.Controls.Add(btnStop);
        }
    }
}


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

上一主题上一主题         下一主题下一主题
QQ手机版小黑屋粤ICP备17165530号

关于我们·投诉举报· 用户帮助· 联系我们 · 本站服务 · 版权声明· 隐私政策 · 投搞指南

法律保护:PLC技术网,plcjs.com,plcjs.net等字样
Copyright 2010-2030. All rights reserved. 


微信公众号二维码 抖音二维码 百家号二维码 今日头条二维码哔哩哔哩二维码