Windows1.xaml
1: <Window x:Class="EightBall.Windows1"2: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"3: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"4: Title="Eight Ball Answer" Height="328" Width="412">5: <Grid Name="grid1">6: <Grid.RowDefinitions>7: <RowDefinition Height="*" />8: <RowDefinition Height="Auto" />9: <RowDefinition Height="*" />10: </Grid.RowDefinitions>11: <TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10"12: Name="txtQuestion" TextWrapping="Wrap" FontFamily="Verdana" FontSize="24" Grid.Row="0">13: [Place question here.]14: </TextBox>15: <Button VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,0,0,20"16: Width="127" Height="23" Name="cmdAnswer" Click="cmdAnswer_Click" Grid.Row="1">17: Ask the Eight Ball18: </Button>19: <TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10" Name="txtAnswer" TextWrapping="Wrap"20: IsReadOnly="True" FontFamily="Verdana" FontSize="24" Foreground="Green" Grid.Row="2">21: [Answer will appear here.]22: </TextBox>23:24: <Grid.Background>25: <LinearGradientBrush>26: <LinearGradientBrush.GradientStops>27: <GradientStop Offset="0.00" Color="Red" />28: <GradientStop Offset="0.50" Color="Indigo" />29: <GradientStop Offset="1.00" Color="Violet" />30: </LinearGradientBrush.GradientStops>31: </LinearGradientBrush>32: </Grid.Background>33: </Grid>34: </Window>
Windows1.xaml.cs
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5: using System.Windows;
6: using System.Windows.Controls;
7: using System.Windows.Data;
8: using System.Windows.Documents;
9: using System.Windows.Input;
10: using System.Windows.Media;
11: using System.Windows.Media.Imaging;
12: using System.Windows.Navigation;
13: using System.Windows.Shapes;
14:15: namespace EightBall
16: {17: public partial class Windows1 : Window18: {19: public Windows1()
20: {21: InitializeComponent();22: }23:24: private void cmdAnswer_Click(object sender, RoutedEventArgs e)25: {26: this.Cursor = Cursors.Wait;
27: System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));28:29: AnswerGenerator generator = new AnswerGenerator();
30: txtAnswer.Text = generator.GetRandomAnswer(txtQuestion.Text);31: this.Cursor = null;32: }33: }34: }
AnswerGenerator.cs
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5:6: namespace EightBall
7: {8: class AnswerGenerator
9: {10: string[] answers = new string[]{11: "Ask Again later","Can Not Predict Now","Without a Doubt",12: "Is Decidely So","Concentrate and Ask Again","My Sources Say No",13: "Yes, Definitely","Don't Count On It","Signs Point to Yes",14: "Better Not Tell You Now","Outlook Not So Good","Most Likely",15: "Very Doubtful","As I See It, Yes","My Reply is No","It Is Certain",16: "Yes","You May Rely On It","Outlook Good","Reply Hazy Try Again"};17:18: public string GetRandomAnswer(string question)19: {20: Random rnd = new Random();
21: return answers[rnd.Next(0, answers.Length)];
22: }23: }24: }
运行界面:
作者:银月莲
出处:http://www.cnblogs.com/moonsilvering
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,包括文章,代码,图片等本站内所有资源,否则保留追究法律责任的权利。