简体   繁体   English

为什么弹出窗口上的图标和按钮有时看起来不同?

[英]Why does the icon and buttons on the popup look different sometimes?

I was testing popups with PowerShell when I noticed something weird occurring.当我注意到发生了一些奇怪的事情时,我正在使用 PowerShell 测试弹出窗口。

The icon on the left of the popup looked different compared to another method of showing it.与另一种显示方法相比,弹出窗口左侧的图标看起来不同。 Also, the button styles were different.此外,按钮样式也不同。

These were both run on the same system (Windows 10 Pro), and the code is exactly the same (shown below).它们都在同一个系统(Windows 10 Pro)上运行,并且代码完全相同(如下所示)。 Both were run on PowerShell 5.1.两者都在 PowerShell 5.1 上运行。

Add-Type -AssemblyName PresentationFramework

$result = [System.Windows.MessageBox]::Show("Would you like to continue?", "Continue?", "YesNo", "Information", "No")
Write-Host $result

1. Old Icon and Buttons 1. 旧图标和按钮

The old icon and buttons were created using the typical PowerShell application.旧图标和按钮是使用典型的 PowerShell 应用程序创建的。 I saved the file as a .ps1 file and then ran it like usual.我将文件保存为.ps1文件,然后像往常一样运行它。

$ ./test.ps1

However, it gave me this popup.但是,它给了我这个弹出窗口。 It's normal, but it looks more like a Windows 7 popup than Windows 10.这很正常,但它看起来更像是 Windows 7 的弹出窗口,而不是 Windows 10。

旧弹出窗口


2. New Icon and Buttons 2.新图标和按钮

The new icon and buttons were created using the Windows PowerShell ISE.新图标和按钮是使用 Windows PowerShell ISE 创建的。 It was run without saving the file (just clicked the Run button to execute it).它在没有保存文件的情况下运行(只需单击“运行”按钮即可执行它)。

This gave me a popup I would expect to see on Windows 10.这给了我一个我希望在 Windows 10 上看到的弹出窗口。

新弹出窗口


So, is this behaviour expected?那么,这种行为是预期的吗? Also, why is it happening?另外,为什么会这样?

Solution解决方案

You need to add the following line to your code before the popup.您需要在弹出窗口之前将以下行添加到您的代码中。

[System.Windows.Forms.Application]::EnableVisualStyles()

This will give the popup the new, modern feel to it.这将使弹出窗口具有新的现代感。


Why?为什么?

The reason that this is occurring is because when running this in the PowerShell ISE, it automatically runs it with the EnableVisualStyles option.发生这种情况的原因是,在 PowerShell ISE 中运行它时,它会使用EnableVisualStyles选项自动运行它。

However, when the code is run in PowerShell, it doesn't add the EnableVisualStyles part unless you specify so.但是,当代码在 PowerShell 中运行时,除非您指定,否则它不会添加EnableVisualStyles部分。

This is why the popup looks "older" in PowerShell, but more modern in the PowerShell ISE.这就是为什么弹出窗口在 PowerShell 中看起来“旧”,但在 PowerShell ISE 中更现代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows和Linux中运行时,为什么同一程序看起来不同? - Why does the same program look different when run in Windows and Linux? 为什么malloc有时不起作用? - Why does malloc not work sometimes? 为什么我的消息框看起来与 Windows 10 中显示的不同? - Why does my message box look different from those Windows 10 otherwise shows? 为什么从文件中获取图标时应用程序有时会崩溃? - Why app sometimes crashes when getting Icon from file? 为什么我的窗口中的按钮在C ++中看起来很旧? - Why do the buttons in my window look old in C++? 为什么在调试过程中,窗口标题黑色和按钮有时无框架 - Why are Window Captions Black and Buttons frameless sometimes during debugging 为什么我的文件有时在读取或写入过程中消失? - Why does my file sometimes disappear in the process of reading from it or writing to it? 为什么我的Button看起来像是从1990年开始? - Why does my Button look like it's from 1990? 为什么在执行应用程序时批处理文件有时会挂起? - Why does the batch file sometimes hangs when executing an application? 为什么我的.NET Windows服务有时不会自动启动? - Why does my .NET Windows service not start automatically sometimes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM