Class TelerikAlignHelper
Provides static utility methods for alignment and positioning calculations in Telerik WinControls.
Inheritance
Inherited Members
Namespace: Telerik.WinControls
Assembly: Telerik.WinControls.dll
Syntax
public class TelerikAlignHelper
Remarks
TelerikAlignHelper contains specialized methods for converting between different alignment systems used in Windows Forms and GDI+ rendering. It handles the complexities of translating ContentAlignment values to various string formatting systems, managing right-to-left (RTL) layout transformations, and determining text-image spatial relationships.
Key functionality includes:
- ContentAlignment to TextFormatFlags conversion for GDI text rendering
- ContentAlignment to StringAlignment conversion for GDI+ text rendering
- Right-to-left layout support with automatic alignment translation
- TextImageRelation determination based on content alignment values
- Spatial relationship calculations for image and text positioning
This class is essential for maintaining consistent text and image alignment across different rendering contexts while properly supporting international layouts and accessibility requirements.
Constructors
TelerikAlignHelper()
Declaration
public TelerikAlignHelper()
Methods
ImageAlignToRelation(ContentAlignment)
Converts a System.Drawing.ContentAlignment value to the corresponding System.Windows.Forms.TextImageRelation for image positioning.
Declaration
public static TextImageRelation ImageAlignToRelation(ContentAlignment alignment)
Parameters
System.Drawing.ContentAlignment
alignment
The content alignment value representing where the image should be positioned. |
Returns
System.Windows.Forms.TextImageRelation
A System.Windows.Forms.TextImageRelation value indicating the spatial relationship between image and text based on the specified alignment. |
Remarks
This method uses a pre-computed lookup table to quickly determine the appropriate text-image relationship based on how the image should be aligned. The conversion considers both horizontal and vertical positioning preferences.
This is useful when you have an image alignment preference and need to determine how the image should be positioned relative to text content for optimal layout.
RtlTranslateContent(ContentAlignment)
Translates a System.Drawing.ContentAlignment value for right-to-left (RTL) layout by flipping horizontal alignments.
Declaration
public static ContentAlignment RtlTranslateContent(ContentAlignment align)
Parameters
System.Drawing.ContentAlignment
align
The content alignment value to translate for RTL layout. |
Returns
System.Drawing.ContentAlignment
The translated System.Drawing.ContentAlignment with horizontal alignment flipped: left alignments become right alignments and vice versa, while center and non-horizontal alignments remain unchanged. |
Remarks
This method is essential for supporting right-to-left languages and layouts. It automatically flips horizontal alignments while preserving vertical alignment information.
Translation examples:
- TopLeft ↔ TopRight
- MiddleLeft ↔ MiddleRight
- BottomLeft ↔ BottomRight
- Center alignments and non-horizontal alignments remain unchanged
This method is commonly used in RTL-aware controls to automatically adjust alignment behavior based on the current reading direction.
RtlTranslateRelation(TextImageRelation)
Translates a System.Windows.Forms.TextImageRelation value for right-to-left (RTL) layout by flipping horizontal relationships.
Declaration
public static TextImageRelation RtlTranslateRelation(TextImageRelation relation)
Parameters
System.Windows.Forms.TextImageRelation
relation
The text-image relation to translate for RTL layout. |
Returns
System.Windows.Forms.TextImageRelation
The translated System.Windows.Forms.TextImageRelation with horizontal relationships flipped: ImageBeforeText becomes TextBeforeImage and vice versa, while other relations remain unchanged. |
Remarks
This method ensures that text-image relationships are properly adjusted for right-to-left layouts. In RTL languages, the concept of "before" and "after" is reversed horizontally.
Translation logic:
- ImageBeforeText → TextBeforeImage
- TextBeforeImage → ImageBeforeText
- All other relations (vertical or overlay) remain unchanged
TextAlignToRelation(ContentAlignment)
Converts a System.Drawing.ContentAlignment value to the corresponding System.Windows.Forms.TextImageRelation for text positioning.
Declaration
public static TextImageRelation TextAlignToRelation(ContentAlignment alignment)
Parameters
System.Drawing.ContentAlignment
alignment
The content alignment value representing where the text should be positioned. |
Returns
System.Windows.Forms.TextImageRelation
A System.Windows.Forms.TextImageRelation value indicating the spatial relationship between text and image based on the specified text alignment preference. |
Remarks
This method first determines what the image relationship would be for the given alignment using ImageAlignToRelation(ContentAlignment), then returns the opposite relationship to represent where the text should be positioned relative to the image.
This is useful when you have a text alignment preference and need to determine how the text should be positioned relative to image content for optimal layout.
TranslateAlignment(ContentAlignment)
Converts a System.Drawing.ContentAlignment value to the corresponding System.Drawing.StringAlignment for horizontal alignment in GDI+ rendering.
Declaration
public static StringAlignment TranslateAlignment(ContentAlignment align)
Parameters
System.Drawing.ContentAlignment
align
The content alignment value to convert. |
Returns
System.Drawing.StringAlignment
A System.Drawing.StringAlignment value representing the horizontal alignment: System.Drawing.StringAlignment.Far for right alignments, System.Drawing.StringAlignment.Center for center alignments, or System.Drawing.StringAlignment.Near for left alignments. |
Remarks
This method extracts the horizontal component of a ContentAlignment and translates it to the appropriate StringAlignment for use with GDI+ text rendering methods like Graphics.DrawString.
The conversion logic:
- TopRight, MiddleRight, BottomRight → StringAlignment.Far
- TopCenter, MiddleCenter, BottomCenter → StringAlignment.Center
- TopLeft, MiddleLeft, BottomLeft → StringAlignment.Near
TranslateAlignmentForGDI(ContentAlignment)
Converts a System.Drawing.ContentAlignment value to the corresponding System.Windows.Forms.TextFormatFlags for vertical text alignment in GDI rendering.
Declaration
public static TextFormatFlags TranslateAlignmentForGDI(ContentAlignment align)
Parameters
System.Drawing.ContentAlignment
align
The content alignment value to convert. |
Returns
System.Windows.Forms.TextFormatFlags
A System.Windows.Forms.TextFormatFlags value representing the vertical alignment: System.Windows.Forms.TextFormatFlags.Bottom for bottom alignments, System.Windows.Forms.TextFormatFlags.VerticalCenter for middle alignments, or System.Windows.Forms.TextFormatFlags.GlyphOverhangPadding for top alignments. |
Remarks
This method extracts the vertical component of a ContentAlignment and translates it to the appropriate TextFormatFlags for use with GDI text rendering methods like TextRenderer.DrawText.
The conversion logic:
- BottomLeft, BottomCenter, BottomRight → TextFormatFlags.Bottom
- MiddleLeft, MiddleCenter, MiddleRight → TextFormatFlags.VerticalCenter
- TopLeft, TopCenter, TopRight → TextFormatFlags.GlyphOverhangPadding (default)
TranslateLineAlignment(ContentAlignment)
Converts a System.Drawing.ContentAlignment value to the corresponding System.Drawing.StringAlignment for vertical line alignment in GDI+ rendering.
Declaration
public static StringAlignment TranslateLineAlignment(ContentAlignment align)
Parameters
System.Drawing.ContentAlignment
align
The content alignment value to convert. |
Returns
System.Drawing.StringAlignment
A System.Drawing.StringAlignment value representing the vertical alignment: System.Drawing.StringAlignment.Far for bottom alignments, System.Drawing.StringAlignment.Center for middle alignments, or System.Drawing.StringAlignment.Near for top alignments. |
Remarks
This method extracts the vertical component of a ContentAlignment and translates it to the appropriate StringAlignment for use with GDI+ text rendering methods as the LineAlignment property.
The conversion logic:
- BottomLeft, BottomCenter, BottomRight → StringAlignment.Far
- MiddleLeft, MiddleCenter, MiddleRight → StringAlignment.Center
- TopLeft, TopCenter, TopRight → StringAlignment.Near
TranslateLineAlignmentForGDI(ContentAlignment)
Converts a System.Drawing.ContentAlignment value to the corresponding System.Windows.Forms.TextFormatFlags for horizontal text alignment in GDI rendering.
Declaration
public static TextFormatFlags TranslateLineAlignmentForGDI(ContentAlignment align)
Parameters
System.Drawing.ContentAlignment
align
The content alignment value to convert. |
Returns
System.Windows.Forms.TextFormatFlags
A System.Windows.Forms.TextFormatFlags value representing the horizontal alignment: System.Windows.Forms.TextFormatFlags.Right for right alignments, System.Windows.Forms.TextFormatFlags.HorizontalCenter for center alignments, or System.Windows.Forms.TextFormatFlags.GlyphOverhangPadding for left alignments. |
Remarks
This method extracts the horizontal component of a ContentAlignment and translates it to the appropriate TextFormatFlags for use with GDI text rendering methods.
The conversion logic:
- TopRight, MiddleRight, BottomRight → TextFormatFlags.Right
- TopCenter, MiddleCenter, BottomCenter → TextFormatFlags.HorizontalCenter
- TopLeft, MiddleLeft, BottomLeft → TextFormatFlags.GlyphOverhangPadding (default)