Class TelerikPaintHelper
Provides static utility methods for advanced painting operations, graphics manipulation, and visual effects in Telerik WinControls.
Inheritance
Inherited Members
Namespace: Telerik.WinControls
Assembly: Telerik.WinControls.dll
Syntax
public class TelerikPaintHelper
Remarks
TelerikPaintHelper contains specialized painting and graphics utilities that extend standard .NET drawing capabilities. It includes methods for control rendering, bitmap manipulation, hardware-accelerated drawing operations, and visual effects that leverage Windows native drawing APIs for optimal performance.
Key functionality includes:
- Control snapshot generation for drag-and-drop operations and previews
- Hardware-accelerated BitBlt operations for fast graphics copying
- Desktop Window Manager (DWM) integration for glass effects and composition
- Halftone pattern drawing for selection indicators and visual feedback
- Color blending and mixing calculations for transparency effects
- Windows Aero glass text rendering with glow effects
This class is primarily used internally by Telerik controls for advanced rendering scenarios but can be used by applications that need sophisticated graphics operations beyond standard GDI+ capabilities.
Constructors
TelerikPaintHelper()
Declaration
public TelerikPaintHelper()
Methods
CopyImageFromGraphics(Graphics, Bitmap)
Copies graphics content from a System.Drawing.Graphics object to a destination bitmap using hardware-accelerated BitBlt.
Declaration
public static void CopyImageFromGraphics(Graphics graphics, Bitmap destinationImage)
Parameters
System.Drawing.Graphics
graphics
The source graphics object to copy from. |
System.Drawing.Bitmap
destinationImage
The destination bitmap to receive the copied graphics content. |
Remarks
This method performs a direct pixel copy from the graphics object's device context to the destination bitmap using the Windows BitBlt API. The entire content of the destination bitmap is replaced with pixels from the graphics object.
The copy operation uses the SRCCOPY raster operation, which directly copies source pixels to the destination without any blending or transformation. The graphics object and destination bitmap should have compatible dimensions for optimal results.
This method is useful for capturing specific graphics rendering output or transferring rendered content between different graphics contexts with minimal overhead.
CreateHalftoneBrush()
Creates a Windows GDI brush with a halftone pattern commonly used for selection indicators and visual feedback.
Declaration
public static IntPtr CreateHalftoneBrush()
Returns
System.IntPtr
An System.IntPtr handle to the created brush. The caller is responsible for disposing of this brush using DeleteObject(IntPtr) when no longer needed. |
Remarks
This method creates a standard halftone brush pattern (alternating pixels in a checkerboard-like pattern) that is commonly used in Windows applications for:
- Selection rectangles and marquee indicators
- Resize handles and drag feedback
- Focus indicators and visual cues
- Temporary overlay effects
The brush uses a predefined 8x8 pixel pattern with alternating pixel values that create the distinctive halftone appearance. This is a standard Windows UI pattern that provides clear visual indication while maintaining compatibility with various background colors.
Important: The returned brush handle must be disposed of using DeleteObject(IntPtr) to prevent resource leaks.
DrawGlowingText(Graphics, String, Font, Rectangle, Color, TextFormatFlags)
Renders text with a glow effect using Windows Desktop Window Manager (DWM) when visual styles are enabled.
Declaration
public static void DrawGlowingText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags)
Parameters
System.Drawing.Graphics
graphics
The graphics object to draw on. |
System.String
text
The text to render with a glow effect. |
System.Drawing.Font
font
The font to use for text rendering. |
System.Drawing.Rectangle
bounds
The rectangle bounds for text layout. |
System.Drawing.Color
color
The color of the text. |
System.Windows.Forms.TextFormatFlags
flags
Text formatting flags controlling layout and appearance. |
Remarks
This method leverages Windows DWM (Desktop Window Manager) capabilities to render text with
a glowing effect that's commonly seen in Windows Aero themes. The glow effect is only
applied when System.Windows.Forms.Application.RenderWithVisualStyles is true
.
The glow effect provides:
- Enhanced text visibility over complex backgrounds
- Professional Windows Aero appearance
- Improved readability in glass/transparent regions
If visual styles are not enabled, this method has no effect. Use this for caption text, overlay text, or any text that needs to stand out against varied backgrounds.
DrawHalftoneLine(Rectangle)
Draws a halftone pattern rectangle on the desktop using the desktop window as the drawing surface.
Declaration
public static void DrawHalftoneLine(Rectangle rectangle1)
Parameters
System.Drawing.Rectangle
rectangle1
The rectangle coordinates in screen coordinates where the halftone pattern should be drawn. |
Remarks
This method draws a halftone pattern directly on the desktop, which is useful for:
- Screen capture selection indicators
- Global drag-and-drop feedback
- Full-screen overlay effects
The rectangle coordinates should be in screen coordinates. The pattern is drawn using XOR operations, making it reversible - calling this method twice with the same rectangle will restore the original appearance.
Security Note: This method requires UIPermission for all windows as it draws directly on the desktop.
DrawHalftoneLine(IntPtr, Rectangle, Control)
Draws a halftone pattern rectangle on the specified window using low-level Windows API calls.
Declaration
public static void DrawHalftoneLine(IntPtr windowHandle, Rectangle rectangle1, Control managedBase)
Parameters
System.IntPtr
windowHandle
The handle to the window on which to draw. |
System.Drawing.Rectangle
rectangle1
The rectangle coordinates where the halftone pattern should be drawn. |
System.Windows.Forms.Control
managedBase
The managed control reference for proper resource management, or |
Remarks
This is the core implementation that performs the actual halftone drawing using Windows GDI APIs. It handles device context management, brush creation, and proper resource cleanup automatically.
The method performs these operations:
- Obtains a device context for the specified window
- Creates a halftone brush pattern
- Performs the PatBlt operation to draw the pattern
- Cleans up all resources to prevent leaks
Security Note: This method requires UIPermission for all windows as it performs low-level drawing operations.
DrawHalftoneLine(Control, Rectangle)
Draws a halftone pattern rectangle on the specified control's surface.
Declaration
public static void DrawHalftoneLine(Control canvasControl, Rectangle rectangle1)
Parameters
System.Windows.Forms.Control
canvasControl
The control on which to draw the halftone pattern. |
System.Drawing.Rectangle
rectangle1
The rectangle coordinates relative to the control where the pattern should be drawn. |
Remarks
This method draws a halftone pattern on the specified control's drawing surface, typically used for:
- Control-specific selection indicators
- Drag-and-drop feedback within a control
- Temporary highlighting and visual cues
The rectangle coordinates should be relative to the control's client area. Like the desktop version, this uses XOR operations making the drawing reversible.
GenerateControlSnapshot(Control)
Generates a bitmap image representing the visual appearance of a control or form using the DrawToBitmap method.
Declaration
public static Bitmap GenerateControlSnapshot(Control control)
Parameters
System.Windows.Forms.Control
control
The control or form to capture. Cannot be |
Returns
System.Drawing.Bitmap
A System.Drawing.Bitmap containing the visual representation of the control, or |
Remarks
This method creates a bitmap snapshot of the specified control's current visual appearance. For System.Windows.Forms.Form objects, special handling is applied to capture only the client area, excluding window borders and title bars.
The method handles several edge cases:
- Returns
null
for minimized forms or forms with invalid client dimensions - Returns
null
for controls with zero or negative width/height - Automatically adjusts for form borders to capture only the client rectangle
This method is commonly used for drag-and-drop operations, control previews, and creating thumbnails of UI elements.
GenerateSnapShotWithBitBlt(Control)
Generates a bitmap image of a control using hardware-accelerated BitBlt operations for optimal performance.
Declaration
public static Bitmap GenerateSnapShotWithBitBlt(Control control)
Parameters
System.Windows.Forms.Control
control
The control or form to capture using BitBlt. Cannot be |
Returns
System.Drawing.Bitmap
A System.Drawing.Bitmap containing the visual representation captured via BitBlt, or |
Remarks
This method uses the Windows BitBlt API to perform a direct pixel copy from the control's device context to a bitmap. This approach is generally faster than GenerateControlSnapshot(Control) as it operates at the hardware level and avoids GDI+ overhead.
Key characteristics:
- Uses native BitBlt for hardware-accelerated copying
- Captures the exact pixels as displayed on screen
- For forms, captures only the client area excluding borders
- Provides better performance for large controls or frequent snapshots
This method is preferred when performance is critical, such as during drag operations or real-time control previews.
IsCompositionEnabled()
Determines whether Windows Desktop Window Manager (DWM) composition is enabled on the current system.
Declaration
public static bool IsCompositionEnabled()
Returns
System.Boolean
|
Remarks
DWM composition enables advanced visual effects like glass transparency, window animations, and hardware-accelerated rendering. This method is useful for:
- Determining whether to use glass effects or fallback rendering
- Enabling composition-dependent features like glow text
- Optimizing rendering paths based on hardware capabilities
Composition is typically enabled on Windows Vista and later with Aero themes, but can be disabled by user settings, group policy, or insufficient hardware capabilities.
Mix(Color, Color)
Creates a solid color form a solid background and a semitransparent top color.
Declaration
public static Color Mix(Color background, Color top)
Parameters
System.Drawing.Color
background
The background color. Will be treated as a solid color(the Alpha/Opacity) is not respected. |
System.Drawing.Color
top
The top color with opacity. |
Returns
System.Drawing.Color
|