Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / Drawing / System / Drawing / Design / FontNameEditor.cs / 1 / FontNameEditor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Drawing.Design {
using Microsoft.Win32;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.IO;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel;
using System.Windows.Forms.Design;
///
///
///
/// Provides an editor that paints a glyph for the font name.
///
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name="FullTrust")]
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name="FullTrust")]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name="FullTrust")]
public class FontNameEditor : UITypeEditor {
///
///
/// Determines if this editor supports the painting of a representation
/// of an object's value.
///
public override bool GetPaintValueSupported(ITypeDescriptorContext context) {
return true;
}
///
///
///
/// Paints a representative value of the given object to the provided
/// canvas. Painting should be done within the boundaries of the
/// provided rectangle.
///
///
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public override void PaintValue(PaintValueEventArgs e) {
string fontName = e.Value as string;
if (fontName != null) {
if (fontName == "") {
// don't draw anything if we don't have a value.
return;
}
e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);
FontFamily family = null;
try {
family = new FontFamily(fontName);
}
catch {
// Ignore the exception if the fontName does not exist or is invalid...
// we just won't render a preview of the font at all
}
if (family != null) {
// Believe it or not, not all font families have a "normal" face. Try normal, then italic,
// then bold, then bold italic, then give up.
try {
DrawFontSample(e, family, FontStyle.Regular);
}
catch {
try {
DrawFontSample(e, family, FontStyle.Italic);
}
catch {
try {
DrawFontSample(e, family, FontStyle.Bold);
}
catch {
try {
DrawFontSample(e, family, FontStyle.Bold | FontStyle.Italic);
}
catch {
// No font style we can think of is supported
}
}
}
}
}
e.Graphics.DrawLine(SystemPens.WindowFrame, e.Bounds.Right, e.Bounds.Y, e.Bounds.Right, e.Bounds.Bottom);
}
}
// Tries to render sample of text in specified font and style,
// throwing exception if specified font does not support that style...
//
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")]
static private void DrawFontSample(PaintValueEventArgs e, FontFamily fontFamily, FontStyle fontStyle) {
float fontSize = (float) (e.Bounds.Height / 1.2);
Font font = new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
if (font == null) {
return;
}
try {
e.Graphics.DrawString("abcd", font, SystemBrushes.ActiveCaptionText, e.Bounds);
}
finally {
font.Dispose();
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _emptywebproxy.cs
- ActivityUtilities.cs
- RangeValuePatternIdentifiers.cs
- ConnectionPoint.cs
- ArrayHelper.cs
- XmlSchemaSequence.cs
- FigureHelper.cs
- MetafileHeaderWmf.cs
- DbConnectionPool.cs
- ColorKeyFrameCollection.cs
- TextPattern.cs
- StructuredProperty.cs
- CustomValidator.cs
- DataGridViewCellStateChangedEventArgs.cs
- Compilation.cs
- InstanceKeyCompleteException.cs
- MetafileHeader.cs
- BaseValidator.cs
- TextBox.cs
- Directory.cs
- ZipIOExtraFieldElement.cs
- CDSsyncETWBCLProvider.cs
- RotateTransform.cs
- StorageComplexPropertyMapping.cs
- DataSourceProvider.cs
- CodeRegionDirective.cs
- OptimizerPatterns.cs
- MetafileHeaderWmf.cs
- PersonalizableTypeEntry.cs
- ConstraintCollection.cs
- WindowInteropHelper.cs
- SqlCacheDependencyDatabaseCollection.cs
- AssemblyBuilderData.cs
- MemberNameValidator.cs
- XmlSchemaInferenceException.cs
- XmlCharType.cs
- WindowsSlider.cs
- ReadOnlyDictionary.cs
- KeyBinding.cs
- VectorAnimationBase.cs
- ClientType.cs
- CalendarKeyboardHelper.cs
- HostExecutionContextManager.cs
- EqualityComparer.cs
- RectAnimationClockResource.cs
- WebServiceMethodData.cs
- CommandValueSerializer.cs
- SmtpAuthenticationManager.cs
- DrawingCollection.cs
- Stack.cs
- HMACSHA384.cs
- DataColumn.cs
- SubtreeProcessor.cs
- XmlWriterTraceListener.cs
- JpegBitmapDecoder.cs
- ClockGroup.cs
- xmlglyphRunInfo.cs
- ProvideValueServiceProvider.cs
- WindowsScrollBar.cs
- MatcherBuilder.cs
- StrokeNodeOperations.cs
- ObjectStateEntry.cs
- RegexBoyerMoore.cs
- QualificationDataAttribute.cs
- XmlSchemaFacet.cs
- MsmqBindingMonitor.cs
- FocusChangedEventArgs.cs
- XmlHierarchicalDataSourceView.cs
- PageStatePersister.cs
- PenContext.cs
- PointAnimationUsingKeyFrames.cs
- HiddenFieldPageStatePersister.cs
- DateTimeFormatInfo.cs
- FileAuthorizationModule.cs
- PriorityItem.cs
- UnionCqlBlock.cs
- LinkTarget.cs
- PathGeometry.cs
- AsymmetricCryptoHandle.cs
- SQLDateTime.cs
- SourceLocationProvider.cs
- DataContractSerializerElement.cs
- SqlVersion.cs
- ContainerControlDesigner.cs
- MarginsConverter.cs
- MsmqIntegrationProcessProtocolHandler.cs
- CultureSpecificStringDictionary.cs
- COAUTHINFO.cs
- ZoneLinkButton.cs
- ExpandoObject.cs
- DataRowChangeEvent.cs
- InfoCardSchemas.cs
- RichTextBoxDesigner.cs
- SmtpNetworkElement.cs
- CodeDefaultValueExpression.cs
- SspiWrapper.cs
- SerializationAttributes.cs
- SimpleFieldTemplateFactory.cs
- SqlGenericUtil.cs
- WebServiceData.cs