ProgressBarRenderer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ProgressBarRenderer.cs / 1305376 / ProgressBarRenderer.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 ProgressBar control. 
    ///    
    ///  
    public sealed class ProgressBarRenderer {

       //Make this per-thread, so that different threads can safely use these methods.
       [ThreadStatic] 
       private static VisualStyleRenderer visualStyleRenderer = null;
 
        //cannot instantiate 
       private ProgressBarRenderer() {
       } 

       /// 
       /// 
       ///     
       ///       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 bar. 
       ///    
       /// 
       [
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally 
       ]
       public static void DrawHorizontalBar(Graphics g, Rectangle bounds) { 
           InitializeRenderer(VisualStyleElement.ProgressBar.Bar.Normal); 

           visualStyleRenderer.DrawBackground(g, bounds); 
       }

       /// 
       ///  
       ///    
       ///       Renders a vertical bar. 
       ///     
       /// 
       [ 
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally
       ]
       public static void DrawVerticalBar(Graphics g, Rectangle bounds) {
           InitializeRenderer(VisualStyleElement.ProgressBar.BarVertical.Normal); 

           visualStyleRenderer.DrawBackground(g, bounds); 
       } 

       ///  
       /// 
       ///    
       ///       Renders a number of constant size horizontal chunks in the given bounds.
       ///     
       /// 
       [ 
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally 
       ]
       public static void DrawHorizontalChunks(Graphics g, Rectangle bounds) { 
           InitializeRenderer(VisualStyleElement.ProgressBar.Chunk.Normal);

           visualStyleRenderer.DrawBackground(g, bounds);
       } 

       ///  
       ///  
       ///    
       ///       Renders a number of constant size vertical chunks in the given bounds. 
       ///    
       /// 
       [
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally 
       ]
       public static void DrawVerticalChunks(Graphics g, Rectangle bounds) { 
           InitializeRenderer(VisualStyleElement.ProgressBar.ChunkVertical.Normal); 

           visualStyleRenderer.DrawBackground(g, bounds); 
       }

       /// 
       ///  
       ///    
       ///       Returns the  width/height of a single horizontal/vertical progress bar chunk. 
       ///     
       /// 
       public static int ChunkThickness { 
           get {
               InitializeRenderer(VisualStyleElement.ProgressBar.Chunk.Normal);

               return (visualStyleRenderer.GetInteger(IntegerProperty.ProgressChunkSize)); 
           }
       } 
 
       /// 
       ///  
       ///    
       ///       Returns the  width/height of the space between horizontal/vertical progress bar chunks.
       ///    
       ///  
       public static int ChunkSpaceThickness {
           get { 
               InitializeRenderer(VisualStyleElement.ProgressBar.Chunk.Normal); 

               return (visualStyleRenderer.GetInteger(IntegerProperty.ProgressSpaceSize)); 
           }
       }

       private static void InitializeRenderer(VisualStyleElement element) { 
           if (visualStyleRenderer == null) {
               visualStyleRenderer = new VisualStyleRenderer(element); 
           } 
           else {
               visualStyleRenderer.SetParameters(element); 
           }
       }
    }
} 

// 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 ProgressBar control. 
    ///    
    ///  
    public sealed class ProgressBarRenderer {

       //Make this per-thread, so that different threads can safely use these methods.
       [ThreadStatic] 
       private static VisualStyleRenderer visualStyleRenderer = null;
 
        //cannot instantiate 
       private ProgressBarRenderer() {
       } 

       /// 
       /// 
       ///     
       ///       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 bar. 
       ///    
       /// 
       [
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally 
       ]
       public static void DrawHorizontalBar(Graphics g, Rectangle bounds) { 
           InitializeRenderer(VisualStyleElement.ProgressBar.Bar.Normal); 

           visualStyleRenderer.DrawBackground(g, bounds); 
       }

       /// 
       ///  
       ///    
       ///       Renders a vertical bar. 
       ///     
       /// 
       [ 
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally
       ]
       public static void DrawVerticalBar(Graphics g, Rectangle bounds) {
           InitializeRenderer(VisualStyleElement.ProgressBar.BarVertical.Normal); 

           visualStyleRenderer.DrawBackground(g, bounds); 
       } 

       ///  
       /// 
       ///    
       ///       Renders a number of constant size horizontal chunks in the given bounds.
       ///     
       /// 
       [ 
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally 
       ]
       public static void DrawHorizontalChunks(Graphics g, Rectangle bounds) { 
           InitializeRenderer(VisualStyleElement.ProgressBar.Chunk.Normal);

           visualStyleRenderer.DrawBackground(g, bounds);
       } 

       ///  
       ///  
       ///    
       ///       Renders a number of constant size vertical chunks in the given bounds. 
       ///    
       /// 
       [
           SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") // Using Graphics instead of IDeviceContext intentionally 
       ]
       public static void DrawVerticalChunks(Graphics g, Rectangle bounds) { 
           InitializeRenderer(VisualStyleElement.ProgressBar.ChunkVertical.Normal); 

           visualStyleRenderer.DrawBackground(g, bounds); 
       }

       /// 
       ///  
       ///    
       ///       Returns the  width/height of a single horizontal/vertical progress bar chunk. 
       ///     
       /// 
       public static int ChunkThickness { 
           get {
               InitializeRenderer(VisualStyleElement.ProgressBar.Chunk.Normal);

               return (visualStyleRenderer.GetInteger(IntegerProperty.ProgressChunkSize)); 
           }
       } 
 
       /// 
       ///  
       ///    
       ///       Returns the  width/height of the space between horizontal/vertical progress bar chunks.
       ///    
       ///  
       public static int ChunkSpaceThickness {
           get { 
               InitializeRenderer(VisualStyleElement.ProgressBar.Chunk.Normal); 

               return (visualStyleRenderer.GetInteger(IntegerProperty.ProgressSpaceSize)); 
           }
       }

       private static void InitializeRenderer(VisualStyleElement element) { 
           if (visualStyleRenderer == null) {
               visualStyleRenderer = new VisualStyleRenderer(element); 
           } 
           else {
               visualStyleRenderer.SetParameters(element); 
           }
       }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK