C#抽奖机 WPF
设计页:
<Window x:Class="RandomDome.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="webattack@163.com" Height="350" Width="525">
<Grid Background="Green">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition ></ColumnDefinition>
<ColumnDefinition ></ColumnDefinition>
<ColumnDefinition ></ColumnDefinition>
<ColumnDefinition ></ColumnDefinition>
</Grid.ColumnDefinitions> www.zzzyk.com
<TextBox Name="tbX" Grid.Row="0" Grid.Column="0" Width="100" Height="50" FontSize="24"></TextBox>
<TextBox Name="tbY" Grid.Row="0" Grid.Column="1" Width="100" Height="50" FontSize="24"></TextBox>
<Button Name="btnBegin" Grid.Row="0" Grid.Column="2" Width="100" Height="50" Content="抽奖" Click="btnBegin_Click"></Button>
<Button Name="btnEnd" Grid.Row="0" Grid.Column="3" Width="100" Height="50" Content="暂停" Click="btnEnd_Click"></Button>
</Grid>
</Window>
代码页面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Threading;
using System.Windows.Threading;
namespace RandomDome
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
int i = 1;
int j = 9;
DispatcherTimer dt = new DispatcherTimer();
MediaPlayer player = new MediaPlayer();
private void btnBegin_Click(object sender, RoutedEventArgs e)
{
string mp = Environment.CurrentDirectory;
int a = mp.LastIndexOf('\\');
int b = a - 3;
mp = mp.Substring(0, b);
mp = mp + "\\music\\那一夜.mp3";
player.Open(new Uri(mp, UriKind.RelativeOrAbsolute ));
player.Play();
dt.Interval = TimeSpan.FromMilliseconds(10);
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
void dt_Tick(object sender, EventArgs e)
{
tbX.Text = i.ToString();
tbY.Text = j.ToString();
i++;
j--;
if (i==9)
{
i = 1;
}
if (j==1)
{
j = 9;
}
}
private void btnEnd_Click(object sender, RoutedEventArgs e)
{
player.Stop();
dt.Stop();
}
}
}
补充:软件开发 , C# ,