0
Arrays in window forms application
Hey guys I need to know If the user clicks on Check Guess button, the user’s guesses in the bottom textbox should be loaded into a new char array named guess. Each character in the word array should be compared to each character in the guess array using a loop.
1 Resposta
0
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private string[] words = { "hey", "there", "hello", "world" };
private void btnGuess_Click(object sender, RoutedEventArgs e)
{
Random rand = new Random();
int pick = rand.Next(0, words.Length);
if (textGuess.Text == words[pick])
{
lbResult.Content = "Correct";
}
else
{
lbResult.Content = "Wrong";
}
}
}
WPF layout:
<Window x:Class="GuessAText.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GuessAText"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBox x:Name="textGuess" HorizontalAlignment="Left" Margin="264,129,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="199"/>
<Button x:Name="btnGuess" Content="Button" HorizontalAlignment="Left" Margin="344,0,0,0" VerticalAlignment="Center" Click="btnGuess_Click"/>
<Label x:Name="lbResult" Content="" HorizontalAlignment="Left" Margin="346,252,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>