This documentation is archived and is not being maintained.
CharacterRange Structure
Visual Studio 2010
Specifies a range of character positions within a string.
Assembly: System.Drawing (in System.Drawing.dll)
The CharacterRange type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | CharacterRange | Initializes a new instance of the CharacterRange structure, specifying a range of character positions within a string. |
| Name | Description | |
|---|---|---|
![]() | Equals | Gets a value indicating whether this object is equivalent to the specified object. (Overrides ValueType::Equals(Object).) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Returns the hash code for this instance. (Overrides ValueType::GetHashCode().) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns the fully qualified type name of this instance. (Inherited from ValueType.) |
| Name | Description | |
|---|---|---|
![]() ![]() | Equality | Compares two CharacterRange objects. Gets a value indicating whether the First and Length values of the two CharacterRange objects are equal. |
![]() ![]() | Inequality | Compares two CharacterRange objects. Gets a value indicating whether the First or Length values of the two CharacterRange objects are not equal. |
The following code example demonstrates how to create a CharacterRange and use it to highlight part of a string. This example is designed to be used with Windows Forms. Paste the example into a form and call the HighlightACharacterRange method when handling the form's Paint event, passing e as PaintEventArgs.
void HighlightACharacterRange( PaintEventArgs^ e ) { // Declare the string to draw. String^ message = "This is the string to highlight a word in."; // Declare the word to highlight. String^ searchWord = "string"; // Create a CharacterRange array with the searchWord // location and length. array<CharacterRange>^ temp = {CharacterRange( message->IndexOf( searchWord ), searchWord->Length )}; array<CharacterRange>^ranges = temp; // Construct a StringFormat object. StringFormat^ stringFormat1 = gcnew StringFormat; // Set the ranges on the StringFormat object. stringFormat1->SetMeasurableCharacterRanges( ranges ); // Declare the font to write the message in. System::Drawing::Font^ largeFont = gcnew System::Drawing::Font( FontFamily::GenericSansSerif,16.0F,GraphicsUnit::Pixel ); // Construct a new Rectangle. Rectangle displayRectangle = Rectangle(20,20,200,100); // Convert the Rectangle to a RectangleF. RectangleF displayRectangleF = displayRectangle; // Get the Region to highlight by calling the // MeasureCharacterRanges method. array<System::Drawing::Region^>^charRegion = e->Graphics->MeasureCharacterRanges( message, largeFont, displayRectangleF, stringFormat1 ); // Draw the message string on the form. e->Graphics->DrawString( message, largeFont, Brushes::Blue, displayRectangleF ); // Fill in the region using a semi-transparent color. e->Graphics->FillRegion( gcnew SolidBrush( Color::FromArgb( 50, Color::Fuchsia ) ), charRegion[ 0 ] ); delete largeFont; }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show:
