wpf介绍

1 提问与回答界面:上面是问题,下面是答案:通过ask按钮实现提问与解答

Xaml

<Grid>

    <Grid.RowDefinitions>

      <RowDefinition Height="*" />

      <RowDefinition Height="Auto" />

      <RowDefinition Height="*" />

    </Grid.RowDefinitions>

    <Grid.Background>

      <LinearGradientBrush>

        <LinearGradientBrush.GradientStops>

          <GradientStop Offset="0.00[F1] "  Color="Red" />

          <GradientStop Offset="0.50" Color="Indigo" />

          <GradientStop Offset="1.00" Color="Violet" />

        </LinearGradientBrush.GradientStops>

      </LinearGradientBrush>

    </Grid.Background>

    <TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10" Name="txtQuestion"

             TextWrapping="Wrap" FontFamily="Verdana" FontSize="24"

             Grid.Row="0" >

      [Place question here.]

    </TextBox>

    <Button VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,0,0,20" Width="127" Height="23" Name="cmdAnswer"

            Click="cmdAnswer_Click"

            Grid.Row="1">     

      Ask the Eight Ball

      </Button>

    <TextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,13,10" Name="txtAnswer"

             TextWrapping="Wrap" IsReadOnly="True" FontFamily="Verdana" FontSize="24" Foreground="Green"

             Grid.Row="2">

      [Answer will appear here.]

    </TextBox>   

  </Grid>

 

 

c#

private void cmdAnswer_Click(object sender, RoutedEventArgs e)

        {          

            // Dramatic delay...

            this.Cursor = Cursors.Wait;

            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));

 

            AnswerGenerator generator = new AnswerGenerator();

            txtAnswer.Text = generator.GetRandomAnswer(txtQuestion.Text);

            this.Cursor = null;

        }

 

 

string[] answers = new string[]{

    "Ask Again later","Can Not Predict Now","Without a Doubt",

    "Is Decidely So","Concentrate and Ask Again","My[F2]  Sources Say No",

    "Yes, Definitely","Don't Count On It","Signs Point to Yes",

    "Better Not Tell You Now","Outlook Not So Good","Most Likely",

    "Very Doubtful","As I See It, Yes","My Reply is No","It Is Certain",

"Yes","You May Rely On It","Outlook Good","Reply Hazy Try Again"

 

 

public string GetRandomAnswer[F3] (string question)

        {

 

            Random rnd = new Random();

           

            return answers[rnd.Next(0, answers.Length)];

        }

 

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值