How to prevent the option ?

Андрей Михалевский 3,331 Reputation points
2022-03-30T14:44:20.447+00:00

Hello. I want to make a menu. For example:

Add-Type -AssemblyName System.Windows.Forms  
  
$form = New-Object System.Windows.Forms.Form  
$form.Text = 'Data Entry Form'  
$form.Size = New-Object System.Drawing.Size(300,200)  
$form.StartPosition = 'CenterScreen'  
  
  
$form.Topmost = $true  
$form.ShowDialog()  
  

When I close a menu, I always see "Cancel" in the console

Where does it come from and how to prevent it? When converting to exe, when I close the program, I also get an additional window with the text 'Cancel'

188452-cancel.png

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,558 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 46,816 Reputation points
    2022-03-30T15:03:40.3+00:00

    You're using "ShowDialog" with no options. That produces a modal dialog box. That means you need a way to dismiss the dialog box. Without the "Cancel" (which is the name of the button you used to close the dialog box) you have no way to know why the dialog box was closed and what action to take (if there were multiple choices offered to the user).

    I think you probably wanted to use the "Show" method and not "ShowDialog".

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.