我有一个程序可以在WPF中生成随机彩票号码,但是我不知道如何获取唯一的随机号码。在研究了“ if结构”之后,我进行了此练习,所以我想应该以某种方式使用它,但是我不知道如何使用。
这是我的代码:
private void btnGo_Click(object sender, RoutedEventArgs e)
{
Random rd = new Random();
int marginLeft = 50 + (caPaper.Children.Count * 50);
Ellipse newBall = new Ellipse();
newBall.Fill = new SolidColorBrush(Colors.Red);
newBall.Height = 70;
newBall.Width = 70;
newBall.Margin = new Thickness(marginLeft, 100, 0, 0);
caPaper.Children.Add(newBall);
TextBlock txt1 = new TextBlock();
txt1.FontSize = 20;
txt1.Foreground = Brushes.White;
txt1.Text = " " + rd.Next(1, 45);
Canvas.SetTop(txt1, 120);
Canvas.SetLeft(txt1, marginLeft + 20);
caPaper.Children.Add(txt1);
}
private void btnClear_Click(object sender, RoutedEventArgs e)
{
caPaper.Children.Clear();
}