Posted by: Cirilo Meggiolaro | 12/12/2008

Tip of the day #59 – SystemInformation class

Tip #58 described the system events that may be registered by your application to check some operational system changes like power change, fonts, time and so on.

Let’s check today what the SystemInformation class is and what is available under it.

The SystemInformation class provides access to some environment properties such as power status, monitor count, windows and mouse settings and so on.

Properties

The following static read-only properties are available for the SystemInformation class:

  • int ActiveWindowTrackingDelay: Gets the active window tracking delay;
  • ArrangeDirection ArrangeDirection: Gets a value that indicates the direction in which the operating system arranges minimized windows;
  • ArrangeStartingPosition ArrangeStartingPosition: Gets an System.Windows.Forms.ArrangeStartingPosition value that indicates the starting position from which the operating system arranges minimized windows;
  • BootMode BootMode: Gets a System.Windows.Forms.BootMode value that indicates the boot mode the system was started in;
  • Size Border3DSize: Gets the thickness, in pixels, of a three-dimensional (3-D) style window or system control border;
  • int BorderMultiplierFactor: Gets the border multiplier factor that is used when determining the thickness of a window’s sizing border;
  • Size BorderSize: Gets the thickness, in pixels, of a flat-style window or system control border;
  • Size CaptionButtonSize: Gets the standard size, in pixels, of a button in a window’s title bar;
  • int CaptionHeight: Gets the height, in pixels, of the standard title bar area of a window;
  • int CaretBlinkTime: Gets the caret blink time;
  • int CaretWidth: Gets the width, in pixels, of the caret in edit controls;
  • string ComputerName: Gets the NetBIOS computer name of the local computer;
  • Size CursorSize: Gets the maximum size, in pixels, that a cursor can occupy;
  • bool DbcsEnabled: Gets a value indicating whether the operating system is capable of handling double-byte character set (DBCS) characters;
  • bool DebugOS: Gets a value indicating whether the debug version of USER.EXE is installed;
  • Size DoubleClickSize: Gets the dimensions, in pixels, of the area within which the user must click twice for the operating system to consider the two clicks a double-click;
  • int DoubleClickTime: Gets the maximum number of milliseconds that can elapse between a first click and a second click for the OS to consider the mouse action a double-click;
  • bool DragFullWindows: Gets a value indicating whether the user has enabled full window drag;
  • Size DragSize: Gets the width and height of a rectangle centered on the point the mouse button was pressed, within which a drag operation will not begin;
  • Size FixedFrameBorderSize: Gets the thickness, in pixels, of the frame border of a window that has a caption and is not resizable;
  • int FontSmoothingContrast: Gets the font smoothing contrast value used in ClearType smoothing;
  • int FontSmoothingType: Gets the current type of font smoothing;
  • Size FrameBorderSize: Gets the thickness, in pixels, of the resizing border that is drawn around the perimeter of a window that is being drag resized;
  • bool HighContrast: Gets a value indicating whether the user has enabled the high-contrast mode accessibility feature;
  • int HorizontalFocusThickness: Gets the thickness of the left and right edges of the system focus rectangle, in pixels;
  • int HorizontalResizeBorderThickness: Gets the thickness of the left and right edges of the sizing border around the perimeter of a window being resized, in pixels;
  • int HorizontalScrollBarArrowWidth: Gets the width, in pixels, of the arrow bitmap on the horizontal scroll bar;
  • int HorizontalScrollBarHeight: Gets the default height, in pixels, of the horizontal scroll bar;
  • int HorizontalScrollBarThumbWidth: Gets the width, in pixels, of the scroll box in a horizontal scroll bar;
  • int IconHorizontalSpacing: Gets the width, in pixels, of an icon arrangement cell in large icon view;
  • Size IconSize: Gets the dimensions, in pixels, of the Windows default program icon size;
  • Size IconSpacingSize: Gets the size, in pixels, of the grid square used to arrange icons in a large-icon view;
  • int IconVerticalSpacing: Gets the height, in pixels, of an icon arrangement cell in large icon view;
  • bool IsActiveWindowTrackingEnabled: Gets a value indicating whether active window tracking is enabled;
  • bool IsComboBoxAnimationEnabled: Gets a value indicating whether the slide-open effect for combo boxes is enabled;
  • bool IsDropShadowEnabled: Gets a value indicating whether the drop shadow effect is enabled;
  • bool IsFlatMenuEnabled: Gets a value indicating whether native user menus have a flat menu appearance;
  • bool IsFontSmoothingEnabled: Gets a value indicating whether font smoothing is enabled;
  • bool IsHotTrackingEnabled: Gets a value indicating whether hot tracking of user-interface elements, such as menu names on menu bars, is enabled;
  • bool IsIconTitleWrappingEnabled: Gets a value indicating whether icon-title wrapping is enabled;
  • bool IsKeyboardPreferred: Gets a value indicating whether the user relies on the keyboard instead of the mouse, and prefers applications to display keyboard interfaces that would otherwise be hidden;
  • bool IsListBoxSmoothScrollingEnabled: Gets a value indicating whether the smooth-scrolling effect for list boxes is enabled;
  • bool IsMenuAnimationEnabled: Gets a value indicating whether menu fade or slide animation features are enabled;
  • bool IsMenuFadeEnabled: Gets a value indicating whether menu fade animation is enabled;
  • bool IsMinimizeRestoreAnimationEnabled: Gets a value indicating whether window minimize and restore animation is enabled;
  • bool IsSelectionFadeEnabled: Gets a value indicating whether the selection fade effect is enabled;
  • bool IsSnapToDefaultEnabled: Gets a value indicating whether the snap-to-default-button feature is enabled;
  • bool IsTitleBarGradientEnabled: Gets a value indicating whether the gradient effect for window title bars is enabled;
  • bool IsToolTipAnimationEnabled: Gets a value indicating whether System.Windows.Forms.ToolTip animation is enabled;
  • int KanjiWindowHeight: Gets the height, in pixels, of the Kanji window at the bottom of the screen for double-byte character set (DBCS) versions of Windows;
  • int KeyboardDelay: Gets the keyboard repeat-delay setting;
  • int KeyboardSpeed: Gets the keyboard repeat-speed setting;
  • Size MaxWindowTrackSize: Gets the default maximum dimensions, in pixels, of a window that has a caption and sizing borders;
  • bool MenuAccessKeysUnderlined: Gets a value indicating whether menu access keys are always underlined;
  • Size MenuBarButtonSize: Gets the default width, in pixels, for menu-bar buttons and the height, in pixels, of a menu bar;
  • Size MenuButtonSize: Gets the default dimensions, in pixels, of menu-bar buttons;
  • Size MenuCheckSize: Gets the dimensions, in pixels, of the default size of a menu check mark area;
  • Font MenuFont: Gets the font used to display text on menus;
  • int MenuHeight: Gets the height, in pixels, of one line of a menu;
  • int MenuShowDelay: Gets the time, in milliseconds, that the system waits before displaying a cascaded shortcut menu when the mouse cursor is over a submenu item;
  • bool MidEastEnabled: Gets a value indicating whether the operating system is enabled for the Hebrew and Arabic languages;
  • Size MinimizedWindowSize: Gets the dimensions, in pixels, of a normal minimized window;
  • Size MinimizedWindowSpacingSize: Gets the dimensions, in pixels, of the area each minimized window is allocated when arranged;
  • Size MinimumWindowSize: Gets the minimum width and height for a window, in pixels;
  • Size MinWindowTrackSize: Gets the default minimum dimensions, in pixels, that a window may occupy during a drag resize;
  • int MonitorCount: Gets the number of display monitors on the desktop;
  • bool MonitorsSameDisplayFormat: Gets a value indicating whether all the display monitors are using the same pixel color format;
  • int MouseButtons: Gets the number of buttons on the mouse;
  • bool MouseButtonsSwapped: Gets a value indicating whether the functions of the left and right mouse buttons have been swapped;
  • Size MouseHoverSize: Gets the dimensions, in pixels, of the rectangle within which the mouse pointer has to stay for the mouse hover time before a mouse hover message is generated;
  • int MouseHoverTime: Gets the time, in milliseconds, that the mouse pointer has to stay in the hover rectangle before a mouse hover message is generated;
  • bool MousePresent: Gets a value indicating whether a pointing device is installed;
  • int MouseSpeed: Gets the current mouse speed;
  • bool MouseWheelPresent: Gets a value indicating whether a mouse with a mouse wheel is installed;
  • int MouseWheelScrollDelta: Gets the amount of the delta value of a single mouse wheel rotation increment;
  • int MouseWheelScrollLines: Gets the number of lines to scroll when the mouse wheel is rotated;
  • bool NativeMouseWheelSupport: Gets a value indicating whether the operating system natively supports a mouse wheel;
  • bool Network: Gets a value indicating whether a network connection is present;
  • bool PenWindows: Gets a value indicating whether the Microsoft Windows for Pen Computing extensions are installed;
  • LeftRightAlignment PopupMenuAlignment: Gets the side of pop-up menus that are aligned to the corresponding menu-bar item;
  • PowerStatus PowerStatus: Gets the current system power status;
  • Size PrimaryMonitorMaximizedWindowSize: Gets the default dimensions, in pixels, of a maximized window on the primary display;
  • Size PrimaryMonitorSize: Gets the dimensions, in pixels, of the current video mode of the primary display;
    bool RightAlignedMenus: Gets a value indicating whether drop-down menus are right-aligned with the corresponding menu-bar item;
  • ScreenOrientation ScreenOrientation: Gets the orientation of the screen;
  • bool Secure: Gets a value indicating whether a Security Manager is present on this operating system;
  • bool ShowSounds: Gets a value indicating whether the user prefers that an application present information in visual form in situations when it would present the information in audible form;
  • int SizingBorderWidth: Gets the width, in pixels, of the sizing border drawn around the perimeter of a window being resized;
  • Size SmallCaptionButtonSize: Gets the width, in pixels, of small caption buttons, and the height, in pixels, of small captions;
  • Size SmallIconSize: Gets the dimensions, in pixels, of a small icon;
  • bool TerminalServerSession: Gets a value indicating whether the calling process is associated with a Terminal Services client session;
  • Size ToolWindowCaptionButtonSize: Gets the dimensions, in pixels, of small caption buttons;
  • int ToolWindowCaptionHeight: Gets the height, in pixels, of a tool window caption;
  • bool UIEffectsEnabled: Gets a value indicating whether user interface (UI) effects are enabled or disabled;
  • string UserDomainName: Gets the name of the domain the user belongs to;
  • bool UserInteractive: Gets a value indicating whether the current process is running in user-interactive mode;
  • string UserName: Gets the user name associated with the current thread;
  • int VerticalFocusThickness: Gets the thickness, in pixels, of the top and bottom edges of the system focus rectangle;
  • int VerticalResizeBorderThickness: Gets the thickness, in pixels, of the top and bottom edges of the sizing border around the perimeter of a window being resized;
  • int VerticalScrollBarArrowHeight: Gets the height, in pixels, of the arrow bitmap on the vertical scroll bar;
  • int VerticalScrollBarThumbHeight: Gets the height, in pixels, of the scroll box in a vertical scroll bar;
  • int VerticalScrollBarWidth: Gets the default width, in pixels, of the vertical scroll bar;
  • Rectangle VirtualScreen: Gets the bounds of the virtual screen;
  • Rectangle WorkingArea: Gets the size, in pixels, of the working area of the screen.

How to…

The usage of properties is straightforward. The code snippets below contain some examples about how to retrieve system information:

/// Retrieves the number of monitors
int monitors = SystemInformation.MonitorCount;

/// Retrieves the power status information
PowerStatus powerStatus = SystemInformation.PowerStatus;
Console.WriteLine(“Battery Charge Status: “ + powerStatus.BatteryChargeStatus.ToString());

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: