# C1.Util.DX.DirectWrite.TextLayout.HitTestTextRange

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Util_DX_DirectWrite_TextLayout_HitTestTextRange_" data-uid="C1.Util.DX.DirectWrite.TextLayout.HitTestTextRange*">HitTestTextRange Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Util_DX_DirectWrite_TextLayout_HitTestTextRange_" data-uid="C1.Util.DX.DirectWrite.TextLayout.HitTestTextRange*"></a>
<h4 id="C1_Util_DX_DirectWrite_TextLayout_HitTestTextRange_System_Int32_System_Int32_System_Single_System_Single_" data-uid="C1.Util.DX.DirectWrite.TextLayout.HitTestTextRange(System.Int32,System.Int32,System.Single,System.Single)">HitTestTextRange(int, int, float, float)</h4>
<div class="markdown level1 summary"><p>The application calls this function to get a set of hit-test metrics corresponding to a range of text positions.
One of the main usages is to implement highlight selection of the text string.
The function returns E_NOT_SUFFICIENT_BUFFER, which is equivalent to HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
when the buffer size of hitTestMetrics is too small to hold all the regions calculated by the function.
In this situation, the function sets the output value *actualHitTestMetricsCount to the number of geometries calculated.
The application is responsible for allocating a new buffer of greater size and calling the function again.
A good value to use as an initial value for maxHitTestMetricsCount may be calculated from the following equation:
maxHitTestMetricsCount = lineCount * maxBidiReorderingDepth where lineCount is obtained from the value of the output argument *actualLineCount (from the function IDWriteTextLayout::GetLineLengths), and the maxBidiReorderingDepth value from the DWRITE_TEXT_METRICS structure of the output argument *textMetrics (from the function IDWriteFactory::CreateTextLayout).</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public HitTestMetrics[] HitTestTextRange(int textPosition, int textLength, float originX, float originY)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function HitTestTextRange(textPosition As Integer, textLength As Integer, originX As Single, originY As Single) As HitTestMetrics()</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">textPosition</span></td>
      <td><p>The first text position of the specified range.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">textLength</span></td>
      <td><p>The number of positions of the specified range.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a></td>
      <td><span class="parametername">originX</span></td>
      <td><p>The origin pixel location X at the left of the layout box. This offset is added to the hit-test metrics returned.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a></td>
      <td><span class="parametername">originY</span></td>
      <td><p>The origin pixel location Y at the top of the layout box. This offset is added to the hit-test metrics returned.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.Util.DX.DirectWrite.HitTestMetrics.html">HitTestMetrics</a>[]</td>
      <td><p>a reference to a buffer of the output geometry fully enclosing the specified position range.  The buffer must be at least as large as maxHitTestMetricsCount.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Util_DX_DirectWrite_TextLayout_HitTestTextRange_" data-uid="C1.Util.DX.DirectWrite.TextLayout.HitTestTextRange*"></a>
<h4 id="C1_Util_DX_DirectWrite_TextLayout_HitTestTextRange_System_Int32_System_Int32_System_Single_System_Single_C1_Util_DX_DirectWrite_HitTestMetrics___System_Int32_System_Int32__" data-uid="C1.Util.DX.DirectWrite.TextLayout.HitTestTextRange(System.Int32,System.Int32,System.Single,System.Single,C1.Util.DX.DirectWrite.HitTestMetrics[],System.Int32,System.Int32@)">HitTestTextRange(int, int, float, float, HitTestMetrics[], int, out int)</h4>
<div class="markdown level1 summary"><p>HRESULT IDWriteTextLayout::HitTestTextRange([In] unsigned int textPosition,[In] unsigned int textLength,[In] float originX,[In] float originY,[Out, Buffer, Optional] DWRITE_HIT_TEST_METRICS* hitTestMetrics,[In] unsigned int maxHitTestMetricsCount,[Out] unsigned int* actualHitTestMetricsCount)</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public HResult HitTestTextRange(int textPosition, int textLength, float originX, float originY, HitTestMetrics[] hitTestMetrics, int maxHitTestMetricsCount, out int actualHitTestMetricsCount)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function HitTestTextRange(textPosition As Integer, textLength As Integer, originX As Single, originY As Single, hitTestMetrics As HitTestMetrics(), maxHitTestMetricsCount As Integer, ByRef actualHitTestMetricsCount As Integer) As HResult</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">textPosition</span></td>
      <td></td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">textLength</span></td>
      <td></td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a></td>
      <td><span class="parametername">originX</span></td>
      <td></td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a></td>
      <td><span class="parametername">originY</span></td>
      <td></td>
    </tr>
    <tr>
      <td><a class="xref" href="C1.Util.DX.DirectWrite.HitTestMetrics.html">HitTestMetrics</a>[]</td>
      <td><span class="parametername">hitTestMetrics</span></td>
      <td></td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">maxHitTestMetricsCount</span></td>
      <td></td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">actualHitTestMetricsCount</span></td>
      <td></td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.Util.DX.HResult.html">HResult</a></td>
      <td></td>
    </tr>
  </tbody>
</table>
</div>
