$host.ui.promptforchoice Console GUI box

This topic contains 2 replies, has 2 voices, and was last updated by  Jennyfer Rusnak 3 years, 10 months ago.

  • Author
    Posts
  • #10723

    Jennyfer Rusnak
    Participant

    I have the following code:

    $t = "Location"
    $msg = "What location?"
    $CFT = New-Object System.Management.Automation.Host.ChoiceDescription "&A choice 1", "1"
    $CON = New-Object System.Management.Automation.Host.ChoiceDescription "&B choice 2", "2"
    $ELP = New-Object System.Management.Automation.Host.ChoiceDescription "&C choice 3", "3"
    $options = [System.Management.Automation.Host.ChoiceDescription[]]($CFT, $CON, $ELP)
    $result = $host.ui.PromptForChoice($t, $msg, $options, 1)

    When I run this code in ISE, I get a GUI prompt with buttons to press for the choices.
    When I run this in the console, I get a text prompt.
    I've been searching online to see how I can get the console to give the GUI prompt and all I have found is this:
    "The $host.ui.prompt like the name says, is specific to the host implementation. PowerGui have impemented a custom host / prompt which is GUI based. The default prompt on the console is the text one that you see."
    When I run $host.ui on each (ISE and console) I see the same output.
    Is there a way to temporarily change the console to use the UI that will prompt with the GUI when I run this script?

  • #10724

    Don Jones
    Keymaster

    The host application is responsible for implementing the prompt; the console does not do a dialog, and there's no way to make it. It implements everything as text, including prompts and progress bars.

    You'd need to go with a complete alternative, such as using the .NET Visual Basic MsgBox function. Of course, you don't get granular control over the buttons with that – so the other alternative is to use Windows Forms or WPF to build a dialog from scratch.

  • #10725

    Jennyfer Rusnak
    Participant

    OK thanks, I'll check that out or stick with the text prompt.

You must be logged in to reply to this topic.