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 / ScrollBarRenderer.cs / 1 / ScrollBarRenderer.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms {
using System;
using System.Drawing;
using System.Windows.Forms.VisualStyles;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Win32;
///
///
///
/// This is a rendering class for the ScrollBar control.
///
///
public sealed class ScrollBarRenderer {
//Make this per-thread, so that different threads can safely use these methods.
[ThreadStatic]
private static VisualStyleRenderer visualStyleRenderer = null;
//cannot instantiate
private ScrollBarRenderer() {
}
///
///
///
/// 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 ScrollBar arrow button.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawArrowButton(Graphics g, Rectangle bounds, ScrollBarArrowButtonState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftNormal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalThumb(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalThumb(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb grip.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalThumbGrip(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.GripperHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb grip.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalThumbGrip(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.GripperVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawRightHorizontalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawLeftHorizontalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb in the center of the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawUpperVerticalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.UpperTrackVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb in the center of the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawLowerVerticalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.LowerTrackVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a ScrollBar size box in the center of the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawSizeBox(Graphics g, Rectangle bounds, ScrollBarSizeBoxState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.SizeBox.LeftAlign, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Returns the size of the ScrollBar thumb grip.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetThumbGripSize(Graphics g, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.GripperHorizontal.Normal, (int)state);
return visualStyleRenderer.GetPartSize(g, ThemeSizeType.True);
}
///
///
///
/// Returns the size of the ScrollBar size box.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetSizeBoxSize(Graphics g, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.SizeBox.LeftAlign, (int)state);
return visualStyleRenderer.GetPartSize(g, ThemeSizeType.True);
}
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.Windows.Forms.VisualStyles;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Win32;
///
///
///
/// This is a rendering class for the ScrollBar control.
///
///
public sealed class ScrollBarRenderer {
//Make this per-thread, so that different threads can safely use these methods.
[ThreadStatic]
private static VisualStyleRenderer visualStyleRenderer = null;
//cannot instantiate
private ScrollBarRenderer() {
}
///
///
///
/// 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 ScrollBar arrow button.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawArrowButton(Graphics g, Rectangle bounds, ScrollBarArrowButtonState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftNormal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalThumb(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.ThumbButtonHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalThumb(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb grip.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalThumbGrip(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.GripperHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb grip.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalThumbGrip(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.GripperVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawRightHorizontalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.RightTrackHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal ScrollBar thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawLeftHorizontalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.LeftTrackHorizontal.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb in the center of the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawUpperVerticalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.UpperTrackVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical ScrollBar thumb in the center of the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawLowerVerticalTrack(Graphics g, Rectangle bounds, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.LowerTrackVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a ScrollBar size box in the center of the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawSizeBox(Graphics g, Rectangle bounds, ScrollBarSizeBoxState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.SizeBox.LeftAlign, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Returns the size of the ScrollBar thumb grip.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetThumbGripSize(Graphics g, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.GripperHorizontal.Normal, (int)state);
return visualStyleRenderer.GetPartSize(g, ThemeSizeType.True);
}
///
///
///
/// Returns the size of the ScrollBar size box.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetSizeBoxSize(Graphics g, ScrollBarState state) {
InitializeRenderer(VisualStyleElement.ScrollBar.SizeBox.LeftAlign, (int)state);
return visualStyleRenderer.GetPartSize(g, ThemeSizeType.True);
}
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
- ToolboxDataAttribute.cs
- DataGridCell.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- TableProviderWrapper.cs
- XmlTextAttribute.cs
- IOThreadScheduler.cs
- TypeInitializationException.cs
- URLString.cs
- UndoUnit.cs
- AttributeUsageAttribute.cs
- HostingPreferredMapPath.cs
- MissingMemberException.cs
- SettingsSavedEventArgs.cs
- WorkflowMarkupSerializationProvider.cs
- ScriptingRoleServiceSection.cs
- TextBoxAutomationPeer.cs
- DragDeltaEventArgs.cs
- Tracer.cs
- DBSchemaTable.cs
- RayHitTestParameters.cs
- ModifierKeysConverter.cs
- WebEventTraceProvider.cs
- AppSettingsReader.cs
- SchemaManager.cs
- HttpSessionStateBase.cs
- _CommandStream.cs
- PolygonHotSpot.cs
- OdbcConnectionPoolProviderInfo.cs
- AccessDataSourceDesigner.cs
- ToolTipService.cs
- CollectionView.cs
- FrameworkElement.cs
- InstanceData.cs
- Message.cs
- Path.cs
- HtmlInputButton.cs
- PropertyDescriptorComparer.cs
- DesignerActionVerbList.cs
- XmlCompatibilityReader.cs
- _LocalDataStore.cs
- COM2ComponentEditor.cs
- EncryptedData.cs
- Query.cs
- Zone.cs
- UnsafeNativeMethods.cs
- Stopwatch.cs
- ConfigurationSectionGroup.cs
- CreateRefExpr.cs
- ToolTipService.cs
- ImageAnimator.cs
- X509CertificateTrustedIssuerElement.cs
- OdbcConnectionFactory.cs
- ServiceEndpointAssociationProvider.cs
- EmptyQuery.cs
- DataSourceComponent.cs
- Point4DValueSerializer.cs
- BitmapEffectInput.cs
- ApplicationSettingsBase.cs
- PolicyAssertionCollection.cs
- OrderedDictionaryStateHelper.cs
- DataRecordInternal.cs
- Shape.cs
- WebBrowserNavigatingEventHandler.cs
- UIElement3D.cs
- FrameworkElementFactoryMarkupObject.cs
- ErrorStyle.cs
- DataGridViewCheckBoxColumn.cs
- RegexFCD.cs
- LineProperties.cs
- SpellerInterop.cs
- DesignerDataSchemaClass.cs
- DataRelationCollection.cs
- DeferredElementTreeState.cs
- PerfService.cs
- AssemblyHash.cs
- MemberPath.cs
- SoapExtensionImporter.cs
- XmlSchemaDocumentation.cs
- CqlGenerator.cs
- ReceiveMessageAndVerifySecurityAsyncResultBase.cs
- SoapElementAttribute.cs
- GenericIdentity.cs
- TextTrailingWordEllipsis.cs
- CharEnumerator.cs
- TextDecoration.cs
- TextTreeTextElementNode.cs
- BamlTreeMap.cs
- StyleSheetDesigner.cs
- XmlAttributeOverrides.cs
- OutOfProcStateClientManager.cs
- TypeUtil.cs
- KeySpline.cs
- MissingMethodException.cs
- Point3DKeyFrameCollection.cs
- SrgsText.cs
- TableSectionStyle.cs
- AuthorizationSection.cs
- StrongTypingException.cs
- CompleteWizardStep.cs
- ListBox.cs