Поделиться через


UserPreferenceChangingEventArgs Класс

Определение

Предоставляет данные о событии UserPreferenceChanging.

public ref class UserPreferenceChangingEventArgs : EventArgs
public class UserPreferenceChangingEventArgs : EventArgs
type UserPreferenceChangingEventArgs = class
    inherit EventArgs
Public Class UserPreferenceChangingEventArgs
Inherits EventArgs
Наследование
UserPreferenceChangingEventArgs

Примеры

В следующем примере кода показано, как использовать UserPreferenceChangingEventArgs тип для мониторинга UserPreferenceChanging события. Этот пример входит в состав более крупного примера использования класса SystemEvents.

#using <System.dll>

using namespace System;
using namespace Microsoft::Win32;

// This method is called when a user preference changes.
void SystemEvents_UserPreferenceChanging(Object^ sender,
     UserPreferenceChangingEventArgs^ e)
 {
     Console::WriteLine("The user preference is changing. Category={0}",
         e->Category);
 }

// This method is called when the palette changes.
void SystemEvents_PaletteChanged(Object^ sender, EventArgs^ e)
{
    Console::WriteLine("The palette changed.");
}

// This method is called when the display settings change.
void SystemEvents_DisplaySettingsChanged(Object^ sender,
    EventArgs^ e)
{
    Console::WriteLine("The display settings changed.");
}

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();
}

// This code produces the following output.
//
//  This app is waiting for system events.
//  Press <Enter> to terminate this application.
//  Display Settings changed.
//  User preference is changing. Category=General
using System;
using Microsoft.Win32;

public sealed class App 
{
    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();
    }

    // This method is called when a user preference changes.
    static void SystemEvents_UserPreferenceChanging(object sender, UserPreferenceChangingEventArgs e) 
    {
        Console.WriteLine("The user preference is changing. Category={0}", e.Category);
    }

    // This method is called when the palette changes.
    static void SystemEvents_PaletteChanged(object sender, EventArgs e)
    {
        Console.WriteLine("The palette changed.");
    }

    // This method is called when the display settings change.
    static void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
    {
        Console.WriteLine("The display settings changed.");
    }
}

// This code produces the following output.
// 
//  This app is waiting for system events.
//  Press <Enter> to terminate this application.
//  Display Settings changed.
//  User preference is changing. Category=General
Imports Microsoft.Win32
Imports System.Windows.Forms

Friend Class Form1
    Inherits System.Windows.Forms.Form


    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        '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

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If (components IsNot Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub


    Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        Me.SuspendLayout()

        '
        'Form1
        '
        Me.ClientSize = New System.Drawing.Size(648, 398)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub


    ' This method is called when a user preference changes.
    Private Sub SystemEvents_UserPreferenceChanging( _
    ByVal sender As Object, _
    ByVal e As UserPreferenceChangingEventArgs)

        MessageBox.Show("UserPreferenceChanging: " & _
        e.Category.ToString())
    End Sub


    ' This method is called when the palette changes.
    Private Sub SystemEvents_PaletteChanged( _
    ByVal sender As Object, _
    ByVal e As EventArgs)

        MessageBox.Show("PaletteChanged")

    End Sub


    ' This method is called when the display settings change.
    Private Sub SystemEvents_DisplaySettingsChanged( _
    ByVal sender As Object, _
    ByVal e As EventArgs)

        MessageBox.Show("The display settings changed.")

    End Sub

End Class

Комментарии

Событие UserPreferenceChanging возникает, когда должно быть применено изменение пользовательских предпочтений.

Конструкторы

UserPreferenceChangingEventArgs(UserPreferenceCategory)

Инициализирует новый экземпляр класса UserPreferenceChangingEventArgs, используя заданный идентификатор категории пользовательских параметров.

Свойства

Category

Возвращает категорию изменяемых пользовательских параметров.

Методы

Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Применяется к

См. также раздел