Commit 85c79dd7 authored by Manuel Campana's avatar Manuel Campana
Browse files

Versione Avanzata finita

parent 50abb60b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -7,10 +7,12 @@
        mc:Ignorable="d"
        Title="MainWindow" Height="400" Width="350">
    <Grid>
        <Button x:Name="btnStampa" Content="Stampa" HorizontalAlignment="Left" Margin="120,25,0,0" VerticalAlignment="Top" Width="74" Click="btnStampa_Click"/>
        <Button x:Name="btnStampa" Content="Stampa" HorizontalAlignment="Left" Margin="120,25,0,0" VerticalAlignment="Top" Width="74" Click="btnStampa_Click" FontWeight="Black"
                Background="LightGreen"/>
        <ScrollViewer Margin="10,80,70,10">
            <TextBlock x:Name="txtbStampa" TextWrapping="Wrap" />
        </ScrollViewer>
        <Label x:Name="lblLetteraRotante" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="49" Width="100" FontWeight="Black" FontSize="26"/>
        <Label x:Name="lblLetteraRotante" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="49" Width="100" FontWeight="Black" FontSize="30"/>
        <TextBox x:Name="txtLunghezza" Margin="220,25,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100"/>
    </Grid>
</Window>
+30 −4
Original line number Diff line number Diff line
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@@ -16,7 +17,9 @@ namespace ProgrammazioneAsincrona
    /// </summary>
    public partial class MainWindow : Window
    {
        string frase;
        int contatoreLettere = 0;
        int lunghezza = 5;
        string frase = "";
        string lettera = "";
        Random rnd = new Random();
        char[] lettere = new char[26] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
@@ -24,6 +27,7 @@ namespace ProgrammazioneAsincrona
        {
            InitializeComponent();
            Rolling();
            txtLunghezza.Text = "5";
        }
        private async Task Rolling()
        {
@@ -36,11 +40,33 @@ namespace ProgrammazioneAsincrona
            }
        }

        private void btnStampa_Click(object sender, RoutedEventArgs e)
        private async void btnStampa_Click(object sender, RoutedEventArgs e)
        {
            if (!int.TryParse(txtLunghezza.Text, out int lungo) || lungo <= 0)
            {
                txtLunghezza.BorderThickness = new Thickness(3);
                txtLunghezza.BorderBrush = Brushes.Red; 
                MessageBox.Show("Inserisci un numero valido. Impostata lunghezza a 5");
                lunghezza = 5;
                txtLunghezza.Text = "5";
                txtLunghezza.BorderThickness = new Thickness(1);
                txtLunghezza.BorderBrush = Brushes.Gray;
            }
            else
            {
                lunghezza = lungo;
                if (contatoreLettere < lunghezza)
                {
                    frase = frase + lettera;
                    contatoreLettere++;
                }
                else
                {
                    frase = frase + "\n" + lettera; // Aggiunge a capo E la lettera corrente
                    contatoreLettere = 1; // Reset a 1 perché la prima lettera della nuova riga c'è già
                }
            }
            txtbStampa.Text = frase;
        }

    }
}
 No newline at end of file