Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / TabRenderer.cs / 1305376 / 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; ////// /// 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() { } ////// This is a rendering class for the Tab control. /// ////// /// public static bool IsSupported { get { return VisualStyleRenderer.IsSupported; // no downlevel support } } ////// Returns true if this class is supported for the current OS and user/application settings, /// otherwise returns false. /// ////// /// [ 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 Tab item. /// ////// /// [ 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./// Renders a TabPage. /// ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EndpointInfoCollection.cs
- ThrowHelper.cs
- TrustManagerPromptUI.cs
- SQLSingleStorage.cs
- TitleStyle.cs
- CompilerInfo.cs
- CallInfo.cs
- TableRow.cs
- ExeConfigurationFileMap.cs
- TitleStyle.cs
- OperatorExpressions.cs
- PropertyIDSet.cs
- TrustLevelCollection.cs
- RegexInterpreter.cs
- ResourceReferenceKeyNotFoundException.cs
- InternalBufferManager.cs
- QueryableDataSourceEditData.cs
- DoubleLinkListEnumerator.cs
- FocusChangedEventArgs.cs
- CredentialCache.cs
- HandleCollector.cs
- DataGridCommandEventArgs.cs
- ClientCredentials.cs
- MembershipValidatePasswordEventArgs.cs
- RootDesignerSerializerAttribute.cs
- PolicyLevel.cs
- ReachPageContentSerializerAsync.cs
- IntegerCollectionEditor.cs
- BrowserDefinition.cs
- ProcessThreadCollection.cs
- ClientUtils.cs
- DelegatingMessage.cs
- CommandField.cs
- RuntimeIdentifierPropertyAttribute.cs
- GridPattern.cs
- TimerElapsedEvenArgs.cs
- IndexingContentUnit.cs
- ClientBuildManager.cs
- AdornerDecorator.cs
- NameNode.cs
- ZipIOModeEnforcingStream.cs
- EntityClientCacheKey.cs
- ObjectDataSourceDisposingEventArgs.cs
- MessageEnumerator.cs
- ThousandthOfEmRealDoubles.cs
- PropertyNames.cs
- HebrewNumber.cs
- WindowsClaimSet.cs
- DbgCompiler.cs
- KeyTime.cs
- ToolStripPanelSelectionBehavior.cs
- RunInstallerAttribute.cs
- ShapeTypeface.cs
- SharedPerformanceCounter.cs
- ContentFilePart.cs
- ResourceReader.cs
- HostedImpersonationContext.cs
- SqlDesignerDataSourceView.cs
- WebPartUtil.cs
- BrowserDefinition.cs
- ArgumentException.cs
- TabletDeviceInfo.cs
- RowUpdatingEventArgs.cs
- TdsParserStateObject.cs
- AuthenticateEventArgs.cs
- ADConnectionHelper.cs
- RenderDataDrawingContext.cs
- MouseCaptureWithinProperty.cs
- SingleTagSectionHandler.cs
- QilChoice.cs
- TriggerActionCollection.cs
- WebPartUtil.cs
- PropertyDescriptorCollection.cs
- HtmlShim.cs
- WindowsImpersonationContext.cs
- XPathNavigatorReader.cs
- DataSetViewSchema.cs
- HtmlHistory.cs
- XmlCompatibilityReader.cs
- QilInvokeLateBound.cs
- HttpStreamMessageEncoderFactory.cs
- Style.cs
- ComponentCommands.cs
- CharStorage.cs
- TypeUtils.cs
- Regex.cs
- Vector3DCollectionValueSerializer.cs
- StateManagedCollection.cs
- AutoResizedEvent.cs
- DocumentOrderQuery.cs
- StylusPointPropertyId.cs
- Color.cs
- EastAsianLunisolarCalendar.cs
- VirtualPathProvider.cs
- X509InitiatorCertificateServiceElement.cs
- GlyphsSerializer.cs
- TypeBuilderInstantiation.cs
- CriticalHandle.cs
- FieldBuilder.cs
- DataGridViewCellStyleChangedEventArgs.cs