How to prevent the option ?

Андрей Михалевский 3,461 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 for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. Rich Matheisen 48,026 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.