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 / TabRenderer.cs / 1 / TabRenderer.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms {
using System;
using System.Drawing;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms.Internal;
using System.Windows.Forms.VisualStyles;
using Microsoft.Win32;
///
///
///
/// This is a rendering class for the Tab control.
///
///
public sealed class TabRenderer {
//Make this per-thread, so that different threads can safely use these methods.
[ThreadStatic]
private static VisualStyleRenderer visualStyleRenderer = null;
//cannot instantiate
private TabRenderer() {
}
///
///
///
/// Returns true if this class is supported for the current OS and user/application settings,
/// otherwise returns false.
///
///
public static bool IsSupported {
get {
return VisualStyleRenderer.IsSupported; // no downlevel support
}
}
///
///
///
/// Renders a Tab item.
///
///
[
SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally
]
public static void DrawTabItem(Graphics g, Rectangle bounds, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, TabItemState state) {
DrawTabItem(g, bounds, tabItemText, font, false, state);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, bool focused, TabItemState state) {
DrawTabItem(g, bounds, tabItemText, font,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine,
focused, state);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
Color textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor);
TextRenderer.DrawText(g, tabItemText, font, contentBounds, textColor, flags);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, Image image, Rectangle imageRectangle, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
visualStyleRenderer.DrawImage(g, imageRectangle, image);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, Image image, Rectangle imageRectangle, bool focused, TabItemState state) {
DrawTabItem(g, bounds, tabItemText, font,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine,
image, imageRectangle, focused, state);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, Image image, Rectangle imageRectangle, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
visualStyleRenderer.DrawImage(g, imageRectangle, image);
Color textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor);
TextRenderer.DrawText(g, tabItemText, font, contentBounds, textColor, flags);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a TabPage.
///
///
[
SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally
]
public static void DrawTabPage(Graphics g, Rectangle bounds) {
InitializeRenderer(VisualStyleElement.Tab.Pane.Normal, 0);
visualStyleRenderer.DrawBackground(g, bounds);
}
private static void InitializeRenderer(VisualStyleElement element, int state) {
if (visualStyleRenderer == null) {
visualStyleRenderer = new VisualStyleRenderer(element.ClassName, element.Part, state);
}
else {
visualStyleRenderer.SetParameters(element.ClassName, element.Part, state);
}
}
}
}
// 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.Diagnostics.CodeAnalysis;
using System.Windows.Forms.Internal;
using System.Windows.Forms.VisualStyles;
using Microsoft.Win32;
///
///
///
/// This is a rendering class for the Tab control.
///
///
public sealed class TabRenderer {
//Make this per-thread, so that different threads can safely use these methods.
[ThreadStatic]
private static VisualStyleRenderer visualStyleRenderer = null;
//cannot instantiate
private TabRenderer() {
}
///
///
///
/// Returns true if this class is supported for the current OS and user/application settings,
/// otherwise returns false.
///
///
public static bool IsSupported {
get {
return VisualStyleRenderer.IsSupported; // no downlevel support
}
}
///
///
///
/// Renders a Tab item.
///
///
[
SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally
]
public static void DrawTabItem(Graphics g, Rectangle bounds, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, TabItemState state) {
DrawTabItem(g, bounds, tabItemText, font, false, state);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, bool focused, TabItemState state) {
DrawTabItem(g, bounds, tabItemText, font,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine,
focused, state);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
Color textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor);
TextRenderer.DrawText(g, tabItemText, font, contentBounds, textColor, flags);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, Image image, Rectangle imageRectangle, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
visualStyleRenderer.DrawImage(g, imageRectangle, image);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, Image image, Rectangle imageRectangle, bool focused, TabItemState state) {
DrawTabItem(g, bounds, tabItemText, font,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine,
image, imageRectangle, focused, state);
}
///
///
///
/// Renders a Tab item.
///
///
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, Image image, Rectangle imageRectangle, bool focused, TabItemState state) {
InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
// I need this hack since GetBackgroundContentRectangle() returns same rectangle
// as bounds for this control!
Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3);
visualStyleRenderer.DrawImage(g, imageRectangle, image);
Color textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor);
TextRenderer.DrawText(g, tabItemText, font, contentBounds, textColor, flags);
if (focused) {
ControlPaint.DrawFocusRectangle(g, contentBounds);
}
}
///
///
///
/// Renders a TabPage.
///
///
[
SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally
]
public static void DrawTabPage(Graphics g, Rectangle bounds) {
InitializeRenderer(VisualStyleElement.Tab.Pane.Normal, 0);
visualStyleRenderer.DrawBackground(g, bounds);
}
private static void InitializeRenderer(VisualStyleElement element, int state) {
if (visualStyleRenderer == null) {
visualStyleRenderer = new VisualStyleRenderer(element.ClassName, element.Part, state);
}
else {
visualStyleRenderer.SetParameters(element.ClassName, element.Part, state);
}
}
}
}
// 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
- AppSecurityManager.cs
- BuildProviderAppliesToAttribute.cs
- SqlMetaData.cs
- DictionaryCustomTypeDescriptor.cs
- Transactions.cs
- SystemKeyConverter.cs
- SoapAttributeAttribute.cs
- SourceLocation.cs
- IndicShape.cs
- EdmSchemaError.cs
- EditorPartChrome.cs
- AddInEnvironment.cs
- CompiledQueryCacheKey.cs
- DataSourceHelper.cs
- EnumType.cs
- SystemKeyConverter.cs
- Cursor.cs
- ToolStripMenuItem.cs
- ExceptionAggregator.cs
- LockRecursionException.cs
- validation.cs
- CheckBoxDesigner.cs
- StringTraceRecord.cs
- ReadOnlyCollection.cs
- SerialStream.cs
- CanExecuteRoutedEventArgs.cs
- ColumnResizeUndoUnit.cs
- StylusPointPropertyInfo.cs
- ByteConverter.cs
- TreeWalkHelper.cs
- CodeValidator.cs
- StaticFileHandler.cs
- QilReplaceVisitor.cs
- UserControlCodeDomTreeGenerator.cs
- SystemWebSectionGroup.cs
- ThreadExceptionEvent.cs
- TargetConverter.cs
- LassoHelper.cs
- XmlNodeChangedEventArgs.cs
- PathFigureCollection.cs
- CompositeCollection.cs
- TrailingSpaceComparer.cs
- ButtonColumn.cs
- PageHandlerFactory.cs
- AliasGenerator.cs
- FormatterConverter.cs
- followingquery.cs
- MergeFilterQuery.cs
- ResetableIterator.cs
- messageonlyhwndwrapper.cs
- XslCompiledTransform.cs
- PositiveTimeSpanValidatorAttribute.cs
- NullableBoolConverter.cs
- DataTableReader.cs
- PageStatePersister.cs
- FontCollection.cs
- HtmlPanelAdapter.cs
- ServiceDebugBehavior.cs
- VersionedStream.cs
- CanonicalizationDriver.cs
- ComNativeDescriptor.cs
- WindowsRebar.cs
- EntityParameter.cs
- XmlFileEditor.cs
- List.cs
- IndependentlyAnimatedPropertyMetadata.cs
- HtmlInputFile.cs
- ResourceDisplayNameAttribute.cs
- UIElementParaClient.cs
- BasicExpressionVisitor.cs
- DataGridViewCellValidatingEventArgs.cs
- MimeTypeAttribute.cs
- PersonalizationAdministration.cs
- DataGridViewTopRowAccessibleObject.cs
- RuntimeHandles.cs
- ViewStateModeByIdAttribute.cs
- ResourcesGenerator.cs
- WorkflowOperationErrorHandler.cs
- EntityViewGenerator.cs
- PositiveTimeSpanValidator.cs
- CodeDomDecompiler.cs
- SqlClientPermission.cs
- TdsParserSessionPool.cs
- ZipIOLocalFileHeader.cs
- GridViewAutomationPeer.cs
- TreeView.cs
- TimeSpanConverter.cs
- NetPeerTcpBinding.cs
- TextReturnReader.cs
- VerticalAlignConverter.cs
- webbrowsersite.cs
- ToolStripScrollButton.cs
- WebRequest.cs
- CultureTableRecord.cs
- DivideByZeroException.cs
- TouchPoint.cs
- ExpressionVisitor.cs
- ExpressionBindingCollection.cs
- VirtualDirectoryMappingCollection.cs
- ComAdminInterfaces.cs