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)];
}
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)];
}
相关文章推荐
- (一)WPF Theme Editor介绍
- WPF Step By Step 控件介绍
- WPF介绍之一---认识Windows图形
- 一篇关于WPF“样式”介绍的好文
- WPF布局控件AvalonDock介绍以及应用中遇到的一个问题
- WPF Step By Step -基础知识介绍
- WPF入门教程系列五——Window 介绍
- Extended WPF Toolkit 新控件介绍
- WPF学习(三)--Menu、TabControl和DataGrid控件介绍
- WPF之核心面板(容器)控件简单介绍
- 关于.NET/C#/WCF/WPF 打造IP网络智能视频监控系统的介绍
- WPF介绍之XAML
- WPF中Border控件的属性介绍
- WPF自学入门(六)WPF带标题的内容控件简单介绍
- WPF之Page介绍(以及Page之间的链接)
- WPF-基础知识介绍
- WPF 杂谈——入门介绍
- 介绍WPF中DependencyPropert…
- WPF学习开发历程(二)——WPF介绍
- WPF中控件ListView和DataGrid典型属性介绍