Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / DisplayInformation.cs / 1305376 / DisplayInformation.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms { using Microsoft.Win32; using System.Security; using System.Security.Permissions; internal class DisplayInformation { private static bool highContrast; //whether we are under hight contrast mode private static bool lowRes; //whether we are under low resolution mode private static bool isTerminalServerSession; //whether this application is run on a terminal server (remote desktop) private static bool highContrastSettingValid; //indicates whether the high contrast setting is correct private static bool lowResSettingValid; //indicates whether the low resolution setting is correct private static bool terminalSettingValid; //indicates whether the terminal server setting is correct private static short bitsPerPixel; private static bool dropShadowSettingValid; private static bool dropShadowEnabled; private static bool menuAccessKeysUnderlinedValid; private static bool menuAccessKeysUnderlined; static DisplayInformation() { SystemEvents.UserPreferenceChanging += new UserPreferenceChangingEventHandler(UserPreferenceChanging); SystemEvents.DisplaySettingsChanging += new EventHandler(DisplaySettingsChanging); } public static short BitsPerPixel { get { if (bitsPerPixel == 0) { // we used to iterate through all screens, but // for some reason unused screens can temparily appear // in the AllScreens collection - we would honor the display // setting of an unused screen. // According to EnumDisplayMonitors, a primary screen check should be sufficient bitsPerPixel = (short)Screen.PrimaryScreen.BitsPerPixel; } return bitsPerPixel; } } //////tests to see if the monitor is in low resolution mode (8-bit color depth or less). /// public static bool LowResolution { get { if (lowResSettingValid && !lowRes) { return lowRes; } // dont cache if we're in low resolution. lowRes = BitsPerPixel <= 8; lowResSettingValid = true; return lowRes; } } //////tests to see if we are under high contrast mode /// public static bool HighContrast { get { if (highContrastSettingValid) { return highContrast; } highContrast = SystemInformation.HighContrast; highContrastSettingValid = true; return highContrast; } } public static bool IsDropShadowEnabled { get { if (dropShadowSettingValid) { return dropShadowEnabled; } dropShadowEnabled = SystemInformation.IsDropShadowEnabled; dropShadowSettingValid = true; return dropShadowEnabled; } } //////test to see if we are under terminal server mode /// public static bool TerminalServer { get { if (terminalSettingValid) { return isTerminalServerSession; } isTerminalServerSession = SystemInformation.TerminalServerSession; terminalSettingValid = true; return isTerminalServerSession; } } // return if mnemonic underlines should always be there regardless of ALT public static bool MenuAccessKeysUnderlined { get { if (menuAccessKeysUnderlinedValid) { return menuAccessKeysUnderlined; } menuAccessKeysUnderlined = SystemInformation.MenuAccessKeysUnderlined; menuAccessKeysUnderlinedValid = true; return menuAccessKeysUnderlined; } } //////event handler for change in display setting /// private static void DisplaySettingsChanging(object obj, EventArgs ea) { highContrastSettingValid = false; lowResSettingValid = false; terminalSettingValid = false; dropShadowSettingValid = false; menuAccessKeysUnderlinedValid = false; } //////event handler for change in user preference /// private static void UserPreferenceChanging(object obj, UserPreferenceChangingEventArgs e) { highContrastSettingValid = false; lowResSettingValid = false; terminalSettingValid = false; dropShadowSettingValid = false; bitsPerPixel = 0; if (e.Category == UserPreferenceCategory.General) { menuAccessKeysUnderlinedValid =false; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms { using Microsoft.Win32; using System.Security; using System.Security.Permissions; internal class DisplayInformation { private static bool highContrast; //whether we are under hight contrast mode private static bool lowRes; //whether we are under low resolution mode private static bool isTerminalServerSession; //whether this application is run on a terminal server (remote desktop) private static bool highContrastSettingValid; //indicates whether the high contrast setting is correct private static bool lowResSettingValid; //indicates whether the low resolution setting is correct private static bool terminalSettingValid; //indicates whether the terminal server setting is correct private static short bitsPerPixel; private static bool dropShadowSettingValid; private static bool dropShadowEnabled; private static bool menuAccessKeysUnderlinedValid; private static bool menuAccessKeysUnderlined; static DisplayInformation() { SystemEvents.UserPreferenceChanging += new UserPreferenceChangingEventHandler(UserPreferenceChanging); SystemEvents.DisplaySettingsChanging += new EventHandler(DisplaySettingsChanging); } public static short BitsPerPixel { get { if (bitsPerPixel == 0) { // we used to iterate through all screens, but // for some reason unused screens can temparily appear // in the AllScreens collection - we would honor the display // setting of an unused screen. // According to EnumDisplayMonitors, a primary screen check should be sufficient bitsPerPixel = (short)Screen.PrimaryScreen.BitsPerPixel; } return bitsPerPixel; } } //////tests to see if the monitor is in low resolution mode (8-bit color depth or less). /// public static bool LowResolution { get { if (lowResSettingValid && !lowRes) { return lowRes; } // dont cache if we're in low resolution. lowRes = BitsPerPixel <= 8; lowResSettingValid = true; return lowRes; } } //////tests to see if we are under high contrast mode /// public static bool HighContrast { get { if (highContrastSettingValid) { return highContrast; } highContrast = SystemInformation.HighContrast; highContrastSettingValid = true; return highContrast; } } public static bool IsDropShadowEnabled { get { if (dropShadowSettingValid) { return dropShadowEnabled; } dropShadowEnabled = SystemInformation.IsDropShadowEnabled; dropShadowSettingValid = true; return dropShadowEnabled; } } //////test to see if we are under terminal server mode /// public static bool TerminalServer { get { if (terminalSettingValid) { return isTerminalServerSession; } isTerminalServerSession = SystemInformation.TerminalServerSession; terminalSettingValid = true; return isTerminalServerSession; } } // return if mnemonic underlines should always be there regardless of ALT public static bool MenuAccessKeysUnderlined { get { if (menuAccessKeysUnderlinedValid) { return menuAccessKeysUnderlined; } menuAccessKeysUnderlined = SystemInformation.MenuAccessKeysUnderlined; menuAccessKeysUnderlinedValid = true; return menuAccessKeysUnderlined; } } //////event handler for change in display setting /// private static void DisplaySettingsChanging(object obj, EventArgs ea) { highContrastSettingValid = false; lowResSettingValid = false; terminalSettingValid = false; dropShadowSettingValid = false; menuAccessKeysUnderlinedValid = false; } //////event handler for change in user preference /// private static void UserPreferenceChanging(object obj, UserPreferenceChangingEventArgs e) { highContrastSettingValid = false; lowResSettingValid = false; terminalSettingValid = false; dropShadowSettingValid = false; bitsPerPixel = 0; if (e.Category == UserPreferenceCategory.General) { menuAccessKeysUnderlinedValid =false; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CommandManager.cs
- System.Data_BID.cs
- QilInvoke.cs
- HuffmanTree.cs
- COMException.cs
- XmlSubtreeReader.cs
- ThicknessAnimationBase.cs
- ControlPaint.cs
- ErasingStroke.cs
- XslTransform.cs
- ModelPerspective.cs
- MeshGeometry3D.cs
- ListViewItem.cs
- SearchForVirtualItemEventArgs.cs
- selecteditemcollection.cs
- ValueTable.cs
- EventWaitHandleSecurity.cs
- HwndStylusInputProvider.cs
- HttpCapabilitiesEvaluator.cs
- SqlTypesSchemaImporter.cs
- EditorResources.cs
- MetadataHelper.cs
- XPathNodeIterator.cs
- BooleanSwitch.cs
- DSASignatureFormatter.cs
- TextServicesManager.cs
- ByteAnimationBase.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- SafeMarshalContext.cs
- TypeExtension.cs
- ScrollChrome.cs
- RowUpdatingEventArgs.cs
- NonParentingControl.cs
- NodeLabelEditEvent.cs
- StreamHelper.cs
- DesignerActionPropertyItem.cs
- FileDetails.cs
- BindUriHelper.cs
- ToolStripOverflow.cs
- SelectingProviderEventArgs.cs
- DocumentDesigner.cs
- CustomErrorsSectionWrapper.cs
- FastPropertyAccessor.cs
- SqlClientPermission.cs
- ExecutionContext.cs
- HashStream.cs
- ConstrainedDataObject.cs
- DisplayInformation.cs
- Compiler.cs
- SessionPageStatePersister.cs
- TextFindEngine.cs
- MemoryRecordBuffer.cs
- _CommandStream.cs
- Utils.cs
- MetabaseServerConfig.cs
- GeneralTransform3DCollection.cs
- DefaultValueTypeConverter.cs
- ActivityScheduledQuery.cs
- SecureUICommand.cs
- PanelDesigner.cs
- StringCollection.cs
- UrlRoutingModule.cs
- TextRangeAdaptor.cs
- SqlDataSource.cs
- Number.cs
- AddressHeader.cs
- SecurityKeyUsage.cs
- PolicyException.cs
- BrushConverter.cs
- ScriptIgnoreAttribute.cs
- CapacityStreamGeometryContext.cs
- ImagingCache.cs
- LogWriteRestartAreaAsyncResult.cs
- Funcletizer.cs
- GlyphingCache.cs
- GacUtil.cs
- EventNotify.cs
- NullableDoubleSumAggregationOperator.cs
- SaveRecipientRequest.cs
- SizeAnimation.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- XmlSchemaDocumentation.cs
- AggregateNode.cs
- SoapIncludeAttribute.cs
- UnicodeEncoding.cs
- MulticastDelegate.cs
- ObjectDataProvider.cs
- HttpClientProtocol.cs
- TextEffect.cs
- ComponentCollection.cs
- BindingGroup.cs
- HideDisabledControlAdapter.cs
- WrappedOptions.cs
- X509RecipientCertificateClientElement.cs
- TypeInitializationException.cs
- SqlXml.cs
- ScriptRegistrationManager.cs
- ComboBox.cs
- WebCategoryAttribute.cs
- RecognizerStateChangedEventArgs.cs