Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / TrackBarRenderer.cs / 1 / TrackBarRenderer.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.VisualStyles;
using Microsoft.Win32;
///
///
///
/// This is a rendering class for the TrackBar control.
///
///
public sealed class TrackBarRenderer {
//Make this per-thread, so that different threads can safely use these methods.
[ThreadStatic]
private static VisualStyleRenderer visualStyleRenderer = null;
const int lineWidth = 2;
//cannot instantiate
private TrackBarRenderer() {
}
///
///
///
/// 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 horizontal track.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalTrack(Graphics g, Rectangle bounds) {
InitializeRenderer(VisualStyleElement.TrackBar.Track.Normal, 1);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical track.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalTrack(Graphics g, Rectangle bounds) {
InitializeRenderer(VisualStyleElement.TrackBar.TrackVertical.Normal, 1);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.Thumb.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size left pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawLeftPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbLeft.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size right pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawRightPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbRight.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size top pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawTopPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbTop.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size bottom pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawBottomPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbBottom.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal tick.
///
///
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] // PM team has reviewed and decided on naming changes already
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle) {
if (numTicks <= 0 || bounds.Height <= 0 || bounds.Width <= 0 || g == null) {
return;
}
InitializeRenderer(VisualStyleElement.TrackBar.Ticks.Normal, 1);
//trivial case -- avoid calcs
if (numTicks == 1) {
visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, bounds.Y, lineWidth, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None);
return;
}
float inc = ((float)bounds.Width - lineWidth) / ((float)numTicks - 1);
while (numTicks > 0) {
//draw the nth tick
float x = bounds.X + ((float)(numTicks - 1)) * inc;
visualStyleRenderer.DrawEdge(g, new Rectangle((int)Math.Round(x), bounds.Y, lineWidth, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None);
numTicks--;
}
}
///
///
///
/// Renders a vertical tick.
///
///
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] // PM team has reviewed and decided on naming changes already
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle) {
if (numTicks<=0 || bounds.Height <= 0 || bounds.Width<=0 || g == null ) {
return;
}
InitializeRenderer(VisualStyleElement.TrackBar.TicksVertical.Normal, 1);
//trivial case
if (numTicks == 1) {
visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, bounds.Y, bounds.Width, lineWidth), Edges.Top, edgeStyle, EdgeEffects.None);
return;
}
float inc = ((float)bounds.Height - lineWidth) / ((float)numTicks - 1);
while (numTicks > 0) {
//draw the nth tick
float y = bounds.Y + ((float)(numTicks - 1)) * inc;
visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, (int)Math.Round(y), bounds.Width, lineWidth), Edges.Top, edgeStyle, EdgeEffects.None);
numTicks--;
}
}
///
///
///
/// Returns the size of a left pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetLeftPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbLeft.Normal, (int)state);
return (visualStyleRenderer.GetPartSize(g, ThemeSizeType.True));
}
///
///
///
/// Returns the size of a right pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetRightPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbRight.Normal, (int)state);
return (visualStyleRenderer.GetPartSize(g, ThemeSizeType.True));
}
///
///
///
/// Returns the size of a top pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetTopPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbTop.Normal, (int)state);
return (visualStyleRenderer.GetPartSize(g, ThemeSizeType.True));
}
///
///
///
/// Returns the size of a bottom pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetBottomPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbBottom.Normal, (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.Diagnostics.CodeAnalysis;
using System.Windows.Forms.VisualStyles;
using Microsoft.Win32;
///
///
///
/// This is a rendering class for the TrackBar control.
///
///
public sealed class TrackBarRenderer {
//Make this per-thread, so that different threads can safely use these methods.
[ThreadStatic]
private static VisualStyleRenderer visualStyleRenderer = null;
const int lineWidth = 2;
//cannot instantiate
private TrackBarRenderer() {
}
///
///
///
/// 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 horizontal track.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalTrack(Graphics g, Rectangle bounds) {
InitializeRenderer(VisualStyleElement.TrackBar.Track.Normal, 1);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical track.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalTrack(Graphics g, Rectangle bounds) {
InitializeRenderer(VisualStyleElement.TrackBar.TrackVertical.Normal, 1);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.Thumb.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a vertical thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbVertical.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size left pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawLeftPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbLeft.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size right pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawRightPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbRight.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size top pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawTopPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbTop.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a constant size bottom pointing thumb centered in the given bounds.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawBottomPointingThumb(Graphics g, Rectangle bounds, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbBottom.Normal, (int)state);
visualStyleRenderer.DrawBackground(g, bounds);
}
///
///
///
/// Renders a horizontal tick.
///
///
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] // PM team has reviewed and decided on naming changes already
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawHorizontalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle) {
if (numTicks <= 0 || bounds.Height <= 0 || bounds.Width <= 0 || g == null) {
return;
}
InitializeRenderer(VisualStyleElement.TrackBar.Ticks.Normal, 1);
//trivial case -- avoid calcs
if (numTicks == 1) {
visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, bounds.Y, lineWidth, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None);
return;
}
float inc = ((float)bounds.Width - lineWidth) / ((float)numTicks - 1);
while (numTicks > 0) {
//draw the nth tick
float x = bounds.X + ((float)(numTicks - 1)) * inc;
visualStyleRenderer.DrawEdge(g, new Rectangle((int)Math.Round(x), bounds.Y, lineWidth, bounds.Height), Edges.Left, edgeStyle, EdgeEffects.None);
numTicks--;
}
}
///
///
///
/// Renders a vertical tick.
///
///
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] // PM team has reviewed and decided on naming changes already
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static void DrawVerticalTicks(Graphics g, Rectangle bounds, int numTicks, EdgeStyle edgeStyle) {
if (numTicks<=0 || bounds.Height <= 0 || bounds.Width<=0 || g == null ) {
return;
}
InitializeRenderer(VisualStyleElement.TrackBar.TicksVertical.Normal, 1);
//trivial case
if (numTicks == 1) {
visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, bounds.Y, bounds.Width, lineWidth), Edges.Top, edgeStyle, EdgeEffects.None);
return;
}
float inc = ((float)bounds.Height - lineWidth) / ((float)numTicks - 1);
while (numTicks > 0) {
//draw the nth tick
float y = bounds.Y + ((float)(numTicks - 1)) * inc;
visualStyleRenderer.DrawEdge(g, new Rectangle(bounds.X, (int)Math.Round(y), bounds.Width, lineWidth), Edges.Top, edgeStyle, EdgeEffects.None);
numTicks--;
}
}
///
///
///
/// Returns the size of a left pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetLeftPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbLeft.Normal, (int)state);
return (visualStyleRenderer.GetPartSize(g, ThemeSizeType.True));
}
///
///
///
/// Returns the size of a right pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetRightPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbRight.Normal, (int)state);
return (visualStyleRenderer.GetPartSize(g, ThemeSizeType.True));
}
///
///
///
/// Returns the size of a top pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetTopPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbTop.Normal, (int)state);
return (visualStyleRenderer.GetPartSize(g, ThemeSizeType.True));
}
///
///
///
/// Returns the size of a bottom pointing thumb.
///
///
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
public static Size GetBottomPointingThumbSize(Graphics g, TrackBarThumbState state) {
InitializeRenderer(VisualStyleElement.TrackBar.ThumbBottom.Normal, (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
- UInt16Converter.cs
- XmlTextWriter.cs
- CodeGen.cs
- DateTimePicker.cs
- X509ThumbprintKeyIdentifierClause.cs
- X509ChainPolicy.cs
- ControlPersister.cs
- CapabilitiesPattern.cs
- NetDataContractSerializer.cs
- SerialReceived.cs
- HttpModuleAction.cs
- UrlPath.cs
- PlainXmlSerializer.cs
- FixedSOMLineRanges.cs
- Permission.cs
- ScrollItemPattern.cs
- QuaternionKeyFrameCollection.cs
- RadioButtonList.cs
- SecureConversationServiceCredential.cs
- DataServiceClientException.cs
- RectKeyFrameCollection.cs
- WebPart.cs
- ListViewInsertEventArgs.cs
- FrameworkContentElementAutomationPeer.cs
- UIElementParagraph.cs
- DictionaryMarkupSerializer.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- OutputChannelBinder.cs
- WorkflowDispatchContext.cs
- AttributeCallbackBuilder.cs
- TypeConverterHelper.cs
- ConfigXmlCDataSection.cs
- SectionUpdates.cs
- ContentElement.cs
- X509CertificateRecipientServiceCredential.cs
- TableParagraph.cs
- TokenBasedSet.cs
- AnimatedTypeHelpers.cs
- DiscoveryMessageSequenceCD1.cs
- AnimationTimeline.cs
- FormViewInsertEventArgs.cs
- SkewTransform.cs
- DeferredReference.cs
- OracleCommand.cs
- StrokeCollectionDefaultValueFactory.cs
- DataTemplateSelector.cs
- Package.cs
- AppDomainGrammarProxy.cs
- Config.cs
- ProjectedWrapper.cs
- GraphicsContext.cs
- Double.cs
- EditorPartCollection.cs
- CodeDirectionExpression.cs
- ClientUrlResolverWrapper.cs
- DelegatingConfigHost.cs
- sqlpipe.cs
- PassportPrincipal.cs
- EntityDataSourceWizardForm.cs
- ElasticEase.cs
- NameValuePair.cs
- EventBuilder.cs
- QilTargetType.cs
- SerializationSectionGroup.cs
- DataServiceOperationContext.cs
- AttributeTable.cs
- DesignerToolStripControlHost.cs
- HostingPreferredMapPath.cs
- XmlSignatureManifest.cs
- StorageAssociationTypeMapping.cs
- ErrorFormatter.cs
- RepeaterItem.cs
- NeutralResourcesLanguageAttribute.cs
- UniformGrid.cs
- ListItem.cs
- COM2Properties.cs
- FocusManager.cs
- ConstraintStruct.cs
- Enlistment.cs
- PopupControlService.cs
- BaseCollection.cs
- filewebresponse.cs
- TTSEngineProxy.cs
- ProjectedWrapper.cs
- RegexRunnerFactory.cs
- AttributeEmitter.cs
- HttpStreamXmlDictionaryWriter.cs
- InfoCardPolicy.cs
- NumericPagerField.cs
- MasterPage.cs
- OpenTypeMethods.cs
- FrameworkElementAutomationPeer.cs
- IteratorFilter.cs
- JsonCollectionDataContract.cs
- Queue.cs
- DebugViewWriter.cs
- Journal.cs
- ExpandSegment.cs
- AdapterDictionary.cs
- PipelineModuleStepContainer.cs