0

I'm creating n 8th ball and I'm trying to randomly generate one of the eight phrases into a textbox once a button is tapped and can't get my head around how to get my phrases in a textbox when a button is tapped.

private void Button1_Tapped(object sender, TappedRoutedEventArgs e)
    {
        Random num = new Random();
        int a = num.Next(9);

        switch (a)
        {
            case 0:
               Console.;
                break;
            case 1:
                Console.WriteLine.TextBox("Yes");
                break;
            case 2:
                Console.WriteLine.TextBox("No");
                break;
            case 3:
                Console.WriteLine.TextBox("Maybe");
                break;
            case 4:
                Console.WriteLine.TextBox("You could say that");
                break;
            case 5:
                Console.WriteLine.TextBox("Most certain");
                break;
            case 6:
                Console.WriteLine.TextBox("Dont even try");
                break;
            case 7:
                Console.WriteLine.TextBox("Full steam ahead");
                break;
        }
    }
MarkusEgle
  • 2,795
  • 4
  • 41
  • 61
Mr.black
  • 13
  • 6
  • What's your question? – pmcilreavy Jan 12 '18 at 10:42
  • Where is ur question – Raizzen Jan 12 '18 at 10:42
  • im creating n 8th ball and im trying to randomly generate one of the eight phrases into a textbox once a button is tapped – Mr.black Jan 12 '18 at 10:43
  • 1
    What is Console? What is Consoleline? What is hat Textbox in `case 2:`. Create an [mcve] and include any (compile) errors you get. If Console is a textbox, didn't the IDE offer `.Text` as a property that you could set? – rene Jan 12 '18 at 10:47
  • cheers Ive reloaded my problem sorry about the quality of the question – Mr.black Jan 12 '18 at 10:53
  • Console.WriteLine() normally writes to the Console output in a Console App. Normally your textbox in the wpf app has a variable name. Use this name and then .text and assign it. – MarkusEgle Jan 12 '18 at 11:18

1 Answers1

1

Console.WriteLine() normally writes to the Console output in a Console App. So it seems you are mixing something up...

Your textbox in the wpf app needs to have a variable name e.g. theTextBox and then you assign the string to the .Text property.

private void Button1_Tapped(object sender, TappedRoutedEventArgs e)
{
    Random num = new Random();
    int a = num.Next(9);

    switch (a)
    {
        case 0:
            theTextBox.Text = "";
            break;
        case 1:
            theTextBox.Text = "Yes";
            break;
        case 2:
            theTextBox.Text = "No";
            break;
        case 3:
            theTextBox.Text = "Maybe";
            break;
        case 4:
            theTextBox.Text = "You could say that";
            break;
        case 5:
            theTextBox.Text = "Most certain";
            break;
        case 6:
            theTextBox.Text = "Dont even try";
            break;
        case 7:
            theTextBox.Text = "Full steam ahead";
            break;
    }
}
MarkusEgle
  • 2,795
  • 4
  • 41
  • 61
  • Please mark the question as answered if this was the solution. [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – MarkusEgle Jan 12 '18 at 13:25
  • Cool will do just Im having a problem it wont write the phrase to the textbox once the button is pressed can you help again? – Mr.black Jan 12 '18 at 13:28
  • Just tried it myself in a new WpfApp, with `clicked` event it works. `Tapped` is slightly different. Could try it with `clicked` event? – MarkusEgle Jan 12 '18 at 13:59
  • no joy and does it have to be clicked event if im building the app for a phone? – Mr.black Jan 12 '18 at 14:05
  • Should i be using a switch case or maybe something else? – Mr.black Jan 12 '18 at 14:10
  • What I have seen clicked and tapped are essentially the same. https://stackoverflow.com/questions/13318569/are-click-tapped-and-pointerpressed-synonymous-in-winrt-xaml Now I retested it with an UWP app and with the tapped event. Even then it is now updating the Textbox with random words as expected... There is something else, could you try a small WPF or UWP app under Windows? I can't test it under a phone... I don't know what else to be considered... – MarkusEgle Jan 12 '18 at 14:20