美文网首页
WPF-实现简易抽奖系统

WPF-实现简易抽奖系统

作者: BroadZhang | 来源:发表于2020-05-26 14:07 被阅读0次
image.png

代码:
MainWindow.xaml

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="XX抽奖系统" Height="300" Width="500" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
    <Canvas>
        <Label Name="lblName" Content="XXXXXXX" Canvas.Left="101" Canvas.Top="59" Width="267" Height="69" FontSize="50" RenderTransformOrigin="0.266,0.203"/>
        <Button Content="开始" Name="btnStart" Width="150px" FontSize="30px" Height="50px"  Canvas.Left="52" Canvas.Top="189" Click="BtnStart_Click"/>
        <Button Content="停止" Name="btnEnd" Width="150px" FontSize="30px" Height="50px"  Canvas.Left="233" Canvas.Top="189" Click="BtnEnd_Click"/>
    </Canvas>
</Window>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        
        //定义存放姓名的集合
        List<string> list = new List<string>();
        DispatcherTimer time;
        Random random = new Random();


        /// <summary>
        /// 初始化事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Class1 class1 = new Class1();
          
            Console.WriteLine(class1.FindUser("zhangsan"));



            list.Add("张三");
            list.Add("李四");
            list.Add("王五");
            list.Add("赵六");
        }

        /// <summary>
        /// 开始事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            time = new DispatcherTimer();
            time.Interval = TimeSpan.FromMilliseconds(10);
            time.Tick += Time_Tick;
            time.Start();
        }

        private void Time_Tick(object sender, EventArgs e)
        {
            //判断计时器是否正在运行
            if (time.IsEnabled==true)
            {
                int num = random.Next(0,4);
                lblName.Content= list[num]; 
            }
        }

        /// <summary>
        /// 停止事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnEnd_Click(object sender, RoutedEventArgs e)
        {
            // time.IsEnabled = false;
            lblName.Content = list[0];
            time.Stop();
        }
    }
}

相关文章

  • WPF-实现简易抽奖系统

    代码:MainWindow.xaml MainWindow.xaml.cs

  • 简易版文字抽奖系统

    需要用到 xlsx 和 file-saver 包,如果有帮助,还请点个赞哟! css动画 主体代码 配置页 项目地...

  • 抽奖系统实现总结

    技术架构:java + redis + mysql 系统定位*:作为承接前台老虎机等各种游戏功能,后台对接第三方各...

  • python 简易推荐系统实现

    本文是参考了阿里云的推荐系统搭建文章的一个学习笔记,因为原文章的数据集找不到了,所以用的是不同的数据集(可能是有所...

  • 2019-07-03 log4j2 自定义ElasticSear

    简易自定义ElasticSearchAppender 通过自定义appender可实现日志系统日志直接存储到ES ...

  • iOS 抽奖轮盘效果实现思路

    iOS 抽奖轮盘效果实现思路 iOS 抽奖轮盘效果实现思路

  • 抽奖系统

    如下是功能实现的代码:

  • 抽奖系统

    try{ bool flag = true; //用于判断是否继续执行 string name; int key...

  • 抽奖系统

    代码: namespace ConsoleApplication1 { class Program { ...

  • 基于Java的抽奖逻辑

    小组在做一个抽奖系统,现在给我分配到了抽奖逻辑这方面的实现。EMMM,拿到分配的时候是懵B的。 追加: 没有多余讲...

网友评论

      本文标题:WPF-实现简易抽奖系统

      本文链接:https://www.haomeiwen.com/subject/ymomahtx.html