Class
TelerikPaintHelper

Provides static utility methods for advanced painting operations, graphics manipulation, and visual effects in Telerik WinControls.

Definition

Namespace:Telerik.WinControls

Assembly:Telerik.WinControls.dll

Syntax:

cs-api-definition
public class TelerikPaintHelper

Inheritance: objectTelerikPaintHelper

Constructors

TelerikPaintHelper()

Declaration

cs-api-definition
public TelerikPaintHelper()

Methods

CopyImageFromGraphics(Graphics, Bitmap)

Copies graphics content from a Graphics object to a destination bitmap using hardware-accelerated BitBlt.

Declaration

cs-api-definition
public static void CopyImageFromGraphics(Graphics graphics, Bitmap destinationImage)

Parameters

graphics

Graphics

The source graphics object to copy from.

destinationImage

Bitmap

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

cs-api-definition
public static IntPtr CreateHalftoneBrush()

Returns

IntPtr

An 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

cs-api-definition
public static void DrawGlowingText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags)

Parameters

graphics

Graphics

The graphics object to draw on.

text

string

The text to render with a glow effect.

font

Font

The font to use for text rendering.

bounds

Rectangle

The rectangle bounds for text layout.

color

Color

The color of the text.

flags

TextFormatFlags

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 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(Control, Rectangle)

Draws a halftone pattern rectangle on the specified control's surface.

Declaration

cs-api-definition
public static void DrawHalftoneLine(Control canvasControl, Rectangle rectangle1)

Parameters

canvasControl

Control

The control on which to draw the halftone pattern.

rectangle1

Rectangle

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.

DrawHalftoneLine(IntPtr, Rectangle, Control)

Draws a halftone pattern rectangle on the specified window using low-level Windows API calls.

Declaration

cs-api-definition
public static void DrawHalftoneLine(IntPtr windowHandle, Rectangle rectangle1, Control managedBase)

Parameters

windowHandle

IntPtr

The handle to the window on which to draw.

rectangle1

Rectangle

The rectangle coordinates where the halftone pattern should be drawn.

managedBase

Control

The managed control reference for proper resource management, or null for unmanaged scenarios.

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:

  1. Obtains a device context for the specified window
  2. Creates a halftone brush pattern
  3. Performs the PatBlt operation to draw the pattern
  4. Cleans up all resources to prevent leaks

Security Note: This method requires UIPermission for all windows as it performs low-level drawing operations.

DrawHalftoneLine(Rectangle)

Draws a halftone pattern rectangle on the desktop using the desktop window as the drawing surface.

Declaration

cs-api-definition
public static void DrawHalftoneLine(Rectangle rectangle1)

Parameters

rectangle1

Rectangle

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.

GenerateControlSnapshot(Control)

Generates a bitmap image representing the visual appearance of a control or form using the DrawToBitmap method.

Declaration

cs-api-definition
public static Bitmap GenerateControlSnapshot(Control control)

Parameters

control

Control

The control or form to capture. Cannot be null.

Returns

Bitmap

A Bitmap containing the visual representation of the control, or null if the control is null, has invalid dimensions, or is in a non-renderable state.

Remarks

This method creates a bitmap snapshot of the specified control's current visual appearance. For 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

cs-api-definition
public static Bitmap GenerateSnapShotWithBitBlt(Control control)

Parameters

control

Control

The control or form to capture using BitBlt. Cannot be null.

Returns

Bitmap

A Bitmap containing the visual representation captured via BitBlt, or null if the control is null or has invalid dimensions.

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

cs-api-definition
public static bool IsCompositionEnabled()

Returns

bool

true if DWM composition is enabled and available; otherwise, false.

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

cs-api-definition
public static Color Mix(Color background, Color top)

Parameters

background

Color

The background color. Will be treated as a solid color(the Alpha/Opacity) is not respected.

top

Color

The top color with opacity.

Returns

Color