Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / LinkUtilities.cs / 1 / LinkUtilities.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms {
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Globalization;
using System.Security.Permissions;
internal class LinkUtilities {
// IE fonts and colors
static Color ielinkColor = Color.Empty;
static Color ieactiveLinkColor = Color.Empty;
static Color ievisitedLinkColor = Color.Empty;
const string IESettingsRegPath = "Software\\Microsoft\\Internet Explorer\\Settings";
public const string IEMainRegPath = "Software\\Microsoft\\Internet Explorer\\Main";
const string IEAnchorColor = "Anchor Color";
const string IEAnchorColorVisited = "Anchor Color Visited";
const string IEAnchorColorHover = "Anchor Color Hover";
///
///
/// Retrieves a named IE color from the registry. There are constants at the top
/// of this file of the valid names to retrieve.
///
private static Color GetIEColor(string name) {
// SECREVIEW : We are just reading the IE color settings from the registry...
//
// SECUNDONE : This assert doesn't work... assert everything for now...
//
//new RegistryPermission(RegistryPermissionAccess.Read, "HKCU\\" + IESettingsRegPath).Assert();
new RegistryPermission(PermissionState.Unrestricted).Assert();
try {
RegistryKey key = Registry.CurrentUser.OpenSubKey(IESettingsRegPath);
if (key != null) {
// Since this comes from the registry, be very careful about its contents.
//
string s = (string)key.GetValue(name);
if (s != null) {
string[] rgbs = s.Split(new char[] {','});
int[] rgb = new int[3];
int nMax = Math.Min(rgb.Length, rgbs.Length);
//NOTE: if we can't parse rgbs[i], rgb[i] will be set to 0.
for (int i = 0; i < nMax; i++)
{
int.TryParse(rgbs[i], out rgb[i]);
}
return Color.FromArgb(rgb[0], rgb[1], rgb[2]);
}
}
if (string.Equals(name, IEAnchorColor, StringComparison.OrdinalIgnoreCase)) {
return Color.Blue;
}
else if (string.Equals(name, IEAnchorColorVisited, StringComparison.OrdinalIgnoreCase)) {
return Color.Purple;
}
else if (string.Equals(name, IEAnchorColorHover, StringComparison.OrdinalIgnoreCase)) {
return Color.Red;
}
else {
return Color.Red;
}
}
finally {
System.Security.CodeAccessPermission.RevertAssert();
}
}
public static Color IELinkColor {
get {
if (ielinkColor.IsEmpty) {
ielinkColor = GetIEColor(IEAnchorColor);
}
return ielinkColor;
}
}
public static Color IEActiveLinkColor {
get {
if (ieactiveLinkColor.IsEmpty) {
ieactiveLinkColor = GetIEColor(IEAnchorColorHover);
}
return ieactiveLinkColor;
}
}
public static Color IEVisitedLinkColor {
get {
if (ievisitedLinkColor.IsEmpty) {
ievisitedLinkColor = GetIEColor(IEAnchorColorVisited);
}
return ievisitedLinkColor;
}
}
///
///
/// Retrieves the IE settings for link behavior from the registry.
///
public static LinkBehavior GetIELinkBehavior() {
// SECREVIEW : We are just reading the IE color settings from the registry...
//
// SECUNDONE : This assert doesn't work... assert everything for now...
//
//new RegistryPermission(RegistryPermissionAccess.Read, "HKCU\\" + IEMainRegPath).Assert();
new RegistryPermission(PermissionState.Unrestricted).Assert();
try {
RegistryKey key = Registry.CurrentUser.OpenSubKey(IEMainRegPath);
if (key != null) {
string s = (string)key.GetValue("Anchor Underline");
if (s != null && string.Compare(s, "no", true, CultureInfo.InvariantCulture) == 0) {
return LinkBehavior.NeverUnderline;
}
if (s != null && string.Compare(s, "hover", true, CultureInfo.InvariantCulture) == 0) {
return LinkBehavior.HoverUnderline;
}
else {
return LinkBehavior.AlwaysUnderline;
}
}
}
finally {
System.Security.CodeAccessPermission.RevertAssert();
}
return LinkBehavior.AlwaysUnderline;
}
public static void EnsureLinkFonts(Font baseFont, LinkBehavior link, ref Font linkFont, ref Font hoverLinkFont) {
if (linkFont != null && hoverLinkFont != null) {
return;
}
bool underlineLink = true;
bool underlineHover = true;
if (link == LinkBehavior.SystemDefault) {
link = GetIELinkBehavior();
}
switch (link) {
case LinkBehavior.AlwaysUnderline:
underlineLink = true;
underlineHover = true;
break;
case LinkBehavior.HoverUnderline:
underlineLink = false;
underlineHover = true;
break;
case LinkBehavior.NeverUnderline:
underlineLink = false;
underlineHover = false;
break;
}
Font f = baseFont;
// We optimize for the "same" value (never & always) to avoid creating an
// extra font object.
//
if (underlineHover == underlineLink) {
FontStyle style = f.Style;
if (underlineHover) {
style |= FontStyle.Underline;
}
else {
style &= ~FontStyle.Underline;
}
hoverLinkFont = new Font(f, style);
linkFont = hoverLinkFont;
}
else {
FontStyle hoverStyle = f.Style;
if (underlineHover) {
hoverStyle |= FontStyle.Underline;
}
else {
hoverStyle &= ~FontStyle.Underline;
}
hoverLinkFont = new Font(f, hoverStyle);
FontStyle linkStyle = f.Style;
if (underlineLink) {
linkStyle |= FontStyle.Underline;
}
else {
linkStyle &= ~FontStyle.Underline;
}
linkFont = new Font(f, linkStyle);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms {
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Globalization;
using System.Security.Permissions;
internal class LinkUtilities {
// IE fonts and colors
static Color ielinkColor = Color.Empty;
static Color ieactiveLinkColor = Color.Empty;
static Color ievisitedLinkColor = Color.Empty;
const string IESettingsRegPath = "Software\\Microsoft\\Internet Explorer\\Settings";
public const string IEMainRegPath = "Software\\Microsoft\\Internet Explorer\\Main";
const string IEAnchorColor = "Anchor Color";
const string IEAnchorColorVisited = "Anchor Color Visited";
const string IEAnchorColorHover = "Anchor Color Hover";
///
///
/// Retrieves a named IE color from the registry. There are constants at the top
/// of this file of the valid names to retrieve.
///
private static Color GetIEColor(string name) {
// SECREVIEW : We are just reading the IE color settings from the registry...
//
// SECUNDONE : This assert doesn't work... assert everything for now...
//
//new RegistryPermission(RegistryPermissionAccess.Read, "HKCU\\" + IESettingsRegPath).Assert();
new RegistryPermission(PermissionState.Unrestricted).Assert();
try {
RegistryKey key = Registry.CurrentUser.OpenSubKey(IESettingsRegPath);
if (key != null) {
// Since this comes from the registry, be very careful about its contents.
//
string s = (string)key.GetValue(name);
if (s != null) {
string[] rgbs = s.Split(new char[] {','});
int[] rgb = new int[3];
int nMax = Math.Min(rgb.Length, rgbs.Length);
//NOTE: if we can't parse rgbs[i], rgb[i] will be set to 0.
for (int i = 0; i < nMax; i++)
{
int.TryParse(rgbs[i], out rgb[i]);
}
return Color.FromArgb(rgb[0], rgb[1], rgb[2]);
}
}
if (string.Equals(name, IEAnchorColor, StringComparison.OrdinalIgnoreCase)) {
return Color.Blue;
}
else if (string.Equals(name, IEAnchorColorVisited, StringComparison.OrdinalIgnoreCase)) {
return Color.Purple;
}
else if (string.Equals(name, IEAnchorColorHover, StringComparison.OrdinalIgnoreCase)) {
return Color.Red;
}
else {
return Color.Red;
}
}
finally {
System.Security.CodeAccessPermission.RevertAssert();
}
}
public static Color IELinkColor {
get {
if (ielinkColor.IsEmpty) {
ielinkColor = GetIEColor(IEAnchorColor);
}
return ielinkColor;
}
}
public static Color IEActiveLinkColor {
get {
if (ieactiveLinkColor.IsEmpty) {
ieactiveLinkColor = GetIEColor(IEAnchorColorHover);
}
return ieactiveLinkColor;
}
}
public static Color IEVisitedLinkColor {
get {
if (ievisitedLinkColor.IsEmpty) {
ievisitedLinkColor = GetIEColor(IEAnchorColorVisited);
}
return ievisitedLinkColor;
}
}
///
///
/// Retrieves the IE settings for link behavior from the registry.
///
public static LinkBehavior GetIELinkBehavior() {
// SECREVIEW : We are just reading the IE color settings from the registry...
//
// SECUNDONE : This assert doesn't work... assert everything for now...
//
//new RegistryPermission(RegistryPermissionAccess.Read, "HKCU\\" + IEMainRegPath).Assert();
new RegistryPermission(PermissionState.Unrestricted).Assert();
try {
RegistryKey key = Registry.CurrentUser.OpenSubKey(IEMainRegPath);
if (key != null) {
string s = (string)key.GetValue("Anchor Underline");
if (s != null && string.Compare(s, "no", true, CultureInfo.InvariantCulture) == 0) {
return LinkBehavior.NeverUnderline;
}
if (s != null && string.Compare(s, "hover", true, CultureInfo.InvariantCulture) == 0) {
return LinkBehavior.HoverUnderline;
}
else {
return LinkBehavior.AlwaysUnderline;
}
}
}
finally {
System.Security.CodeAccessPermission.RevertAssert();
}
return LinkBehavior.AlwaysUnderline;
}
public static void EnsureLinkFonts(Font baseFont, LinkBehavior link, ref Font linkFont, ref Font hoverLinkFont) {
if (linkFont != null && hoverLinkFont != null) {
return;
}
bool underlineLink = true;
bool underlineHover = true;
if (link == LinkBehavior.SystemDefault) {
link = GetIELinkBehavior();
}
switch (link) {
case LinkBehavior.AlwaysUnderline:
underlineLink = true;
underlineHover = true;
break;
case LinkBehavior.HoverUnderline:
underlineLink = false;
underlineHover = true;
break;
case LinkBehavior.NeverUnderline:
underlineLink = false;
underlineHover = false;
break;
}
Font f = baseFont;
// We optimize for the "same" value (never & always) to avoid creating an
// extra font object.
//
if (underlineHover == underlineLink) {
FontStyle style = f.Style;
if (underlineHover) {
style |= FontStyle.Underline;
}
else {
style &= ~FontStyle.Underline;
}
hoverLinkFont = new Font(f, style);
linkFont = hoverLinkFont;
}
else {
FontStyle hoverStyle = f.Style;
if (underlineHover) {
hoverStyle |= FontStyle.Underline;
}
else {
hoverStyle &= ~FontStyle.Underline;
}
hoverLinkFont = new Font(f, hoverStyle);
FontStyle linkStyle = f.Style;
if (underlineLink) {
linkStyle |= FontStyle.Underline;
}
else {
linkStyle &= ~FontStyle.Underline;
}
linkFont = new Font(f, linkStyle);
}
}
}
}
// 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
- CodeTypeOfExpression.cs
- ToolStripStatusLabel.cs
- DataGridViewRowsRemovedEventArgs.cs
- DataList.cs
- SqlCommand.cs
- arc.cs
- WebPartDescriptionCollection.cs
- XmlBinaryReader.cs
- UInt64Converter.cs
- ListDataHelper.cs
- NavigateEvent.cs
- DataGridToolTip.cs
- EntityDesignerUtils.cs
- _LazyAsyncResult.cs
- FillBehavior.cs
- NativeBuffer.cs
- IssuedTokensHeader.cs
- LocalValueEnumerator.cs
- ScriptHandlerFactory.cs
- RoutingEndpointTrait.cs
- XamlWriterExtensions.cs
- CookielessHelper.cs
- XmlSerializableWriter.cs
- EmptyImpersonationContext.cs
- BitmapEffectInputConnector.cs
- CommunicationObjectManager.cs
- DrawingAttributesDefaultValueFactory.cs
- TemplateKeyConverter.cs
- Site.cs
- MimeTextImporter.cs
- FrameworkElement.cs
- BaseParaClient.cs
- AvTrace.cs
- X509Certificate2.cs
- RectIndependentAnimationStorage.cs
- DynamicUpdateCommand.cs
- IListConverters.cs
- PartialCachingControl.cs
- DecimalConverter.cs
- DiagnosticsConfiguration.cs
- DataServiceRequest.cs
- SafeCryptContextHandle.cs
- DrawingContextWalker.cs
- TextEncodedRawTextWriter.cs
- DefaultValidator.cs
- FunctionDetailsReader.cs
- ServicePoint.cs
- wmiprovider.cs
- RIPEMD160Managed.cs
- SchemaElementDecl.cs
- TraceContext.cs
- StylusPointPropertyInfoDefaults.cs
- StringValueSerializer.cs
- XamlStream.cs
- Separator.cs
- MultilineStringEditor.cs
- SingleAnimation.cs
- EditorPartChrome.cs
- HandlerBase.cs
- WaitHandle.cs
- NamespaceQuery.cs
- FixedSOMPage.cs
- CryptoHandle.cs
- StylusPointPropertyInfo.cs
- MergeFilterQuery.cs
- LazyTextWriterCreator.cs
- ToolBar.cs
- BoolLiteral.cs
- SmtpTransport.cs
- MessageContractAttribute.cs
- CalendarDateChangedEventArgs.cs
- SingleObjectCollection.cs
- BinaryObjectReader.cs
- FlowDocument.cs
- RefreshPropertiesAttribute.cs
- UrlPath.cs
- HttpApplicationFactory.cs
- ClrPerspective.cs
- DataGridViewComboBoxColumn.cs
- GridViewSortEventArgs.cs
- RegexCode.cs
- TcpProcessProtocolHandler.cs
- XPathDocumentBuilder.cs
- SizeChangedInfo.cs
- HttpPostProtocolImporter.cs
- BitmapEffectGroup.cs
- PeerNodeTraceRecord.cs
- _AutoWebProxyScriptWrapper.cs
- BooleanToVisibilityConverter.cs
- MessageSmuggler.cs
- VisualStyleInformation.cs
- StoreContentChangedEventArgs.cs
- BindingNavigator.cs
- SqlSelectStatement.cs
- DataRowComparer.cs
- DataColumnMappingCollection.cs
- Size3DValueSerializer.cs
- AssemblyUtil.cs
- _LocalDataStoreMgr.cs
- SchemaInfo.cs