$host.ui.promptforchoice Console GUI box
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?
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.
OK thanks, I'll check that out or stick with the text prompt.
You must be logged in to reply to this topic.