SystemEvents.UserPreferenceChanging 事件

定义

当用户首选项更改时发生。Occurs when a user preference is changing.

public:
 static event Microsoft::Win32::UserPreferenceChangingEventHandler ^ UserPreferenceChanging;
public static event Microsoft.Win32.UserPreferenceChangingEventHandler UserPreferenceChanging;
member this.UserPreferenceChanging : Microsoft.Win32.UserPreferenceChangingEventHandler 
Public Shared Custom Event UserPreferenceChanging As UserPreferenceChangingEventHandler 

异常

当前上下文不支持系统事件通知。System event notifications are not supported under the current context. 例如,服务器进程可能不支持全局系统事件通知。Server processes, for example, might not support global system event notifications.

创建系统事件窗口线程的尝试未成功。The attempt to create a system events window thread did not succeed.

示例

下面的代码示例演示如何监视 UserPreferenceChanging 事件。The following code example demonstrates how to monitor the UserPreferenceChanging event. 此代码示例是为 SystemEvents 类提供的更大示例的一部分。This code example is part of a larger example provided for the SystemEvents class.

int main()
{
    // Set the SystemEvents class to receive event notification
    // when a user preference changes, the palette changes, or
    // when display settings change.
    SystemEvents::UserPreferenceChanging += gcnew
        UserPreferenceChangingEventHandler(
        SystemEvents_UserPreferenceChanging);
    SystemEvents::PaletteChanged += gcnew
        EventHandler(SystemEvents_PaletteChanged);
    SystemEvents::DisplaySettingsChanged += gcnew
        EventHandler(SystemEvents_DisplaySettingsChanged);

    // For demonstration purposes, this application sits idle
    // waiting for events.
    Console::WriteLine("This application is waiting for system events.");
    Console::WriteLine("Press <Enter> to terminate this application.");
    Console::ReadLine();
}
static void Main() 
{         
    // Set the SystemEvents class to receive event notification when a user 
    // preference changes, the palette changes, or when display settings change.
    SystemEvents.UserPreferenceChanging += new 
        UserPreferenceChangingEventHandler(SystemEvents_UserPreferenceChanging);
    SystemEvents.PaletteChanged += new 
        EventHandler(SystemEvents_PaletteChanged);
    SystemEvents.DisplaySettingsChanged += new 
        EventHandler(SystemEvents_DisplaySettingsChanged);        

    // For demonstration purposes, this application sits idle waiting for events.
    Console.WriteLine("This application is waiting for system events.");
    Console.WriteLine("Press <Enter> to terminate this application.");
    Console.ReadLine();
}
'Set the SystemEvents class to receive event notification 
'when a user preference changes, the palette changes, or 
'when display settings change.
AddHandler SystemEvents.UserPreferenceChanging, _
AddressOf SystemEvents_UserPreferenceChanging

AddHandler SystemEvents.PaletteChanged, _
AddressOf SystemEvents_PaletteChanged

AddHandler SystemEvents.DisplaySettingsChanged, _
AddressOf SystemEvents_DisplaySettingsChanged

注解

备注

仅当消息泵正在运行时才引发此事件。This event is only raised if the message pump is running. 在 Windows 服务中,除非使用隐藏的窗体或手动启动了消息泵,否则将不会引发此事件。In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. 有关演示如何使用 Windows 服务中的隐藏窗体处理系统事件的代码示例,请参阅 SystemEvents 类。For a code example that shows how to handle system events by using a hidden form in a Windows service, see the SystemEvents class.

注意

因为这是一个静态事件,所以必须在释放应用程序时分离事件处理程序,否则会导致内存泄漏。Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.

适用于

另请参阅