您的位置:首页 > 其它

wpf介绍

2009-12-01 12:21 483 查看
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)];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: