Files
componentowl-astro/public/documentation/better-thumbnail-browser/data/chapter-hit-test.html

234 lines
12 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Hit Test</title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="prettify.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="prettify.js"></script><script type="text/javascript" src="lang-vb.js"></script><link href="../resources/main.css" media="screen" rel="stylesheet" type="text/css">
</head>
<body onload="prettyPrint()"><div class="placing">
<br><table class="navigation"><tr>
<td class="navigation-previous"><a href="chapter-groups.html"><strong>
« Groups</strong></a></td>
<td class="navigation-index"><a href="../../../better-thumbnail-browser/documentation.html"><strong>Index</strong></a></td>
<td class="navigation-next"><a href="chapter-insertion-mark.html"><strong>Insertion Mark »
</strong></a></td>
</tr></table>
<br><h1>Hit Test</h1>
<div class="banner">
<a href="../../../better-thumbnail-browser.html"><img src="../resources/better-thumbnail-browser-overview.gif" alt="Better Thumbnail Browser" class="ss"></a>
<div class="inside">
<div class="text">Better Thumbnail Browser for .NET (C#, VB) - Image thumbnail viewing and loading control</div>
<span class="dbtn-c dbtn-hilight"><span class="dbtn-w"><a href="../../../betterthumbnailbrowser.exe" class="dbtn">Download</a></span></span>
<span class="dbtn-c"><span class="dbtn-w"><a href="../../../better-thumbnail-browser.html" class="dbtn">More Info</a></span></span>
</div>
</div>
<p>Hit test allows you to detect elements and element parts for a
specified position in the control. There are two overrides of the HitTest
method:</p>
<ul style="list-style:none">
<li>
<span class="code">HitTest()</span><ul style="list-style:none"><li>
<p>Returns hit test information for the current mouse
position.</p>
</li></ul>
</li>
<li>
<span class="code">HitTest(Point)</span><ul style="list-style:none"><li>
<p>Returns hit test information for the specified position (in
client coordinates).</p>
</li></ul>
</li>
</ul>
<p>The returned structure <span class="code">BetterListViewHitTestInfo</span> contains
references to Better ListView elements (column, group, item, sub-item),
element parts and even its state information.</p>
<p>Current hit test information changes every time user moves mouse from
one element part to another (or to another element), or when state of the
hovered element changes (e.g. column is pressed). Better ListView raises
<span class="code">BetterListViewHitTestChanged</span> event whenever this occurs.</p>
<h2>BetterListViewHitTestInfo.Locations Property</h2>
<p>Furthermore, this structure contains a <span class="code">Locations</span>
property, which is enumeration with flags of all the cursor locations. Of
course, there is always just a single cursor position, but it can
correspond to multiple locations. For example, when the mouse cursor is
hovers over an item text, the <span class="code">Locations</span> property has the
following value:</p>
<p></p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">BetterListViewHitTestLocations.ContentArea | BetterListViewHitTestLocations.Item | BetterListViewHitTestLocations.ItemSelection | BetterListViewHitTestLocations.ItemText</code></pre>
<p></p>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">BetterListViewHitTestLocations.ContentArea Or BetterListViewHitTestLocations.Item Or BetterListViewHitTestLocations.ItemSelection Or BetterListViewHitTestLocations.ItemText</code></pre>
<p>When the mouse cursor is inside the control, the
<span class="code">Locations</span> property has always the <span class="code">ContentArea</span>
flag on. The same rule applies within Better ListView elements.</p>
<p>To check for some specific location (e.g. expand button of a group),
write the following expression in an <strong><em>if</em></strong>
statement:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">(hitTestInfo.Locations &amp; BetterListViewHitTestLocations.GroupExpandButton) == BetterListViewHitTestLocations.GroupExpandButton</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">(hitTestInfo.Locations And BetterListViewHitTestLocations.GroupExpandButton) = BetterListViewHitTestLocations.GroupExpandButton</code></pre>
<h2>Difference between ItemDisplay and ItemSelection</h2>
<p>There are two items returned by hit test, which are not necessarily
the same: <span class="code">BetterListViewHitTestInfo.ItemDisplay</span> and
<span class="code">BetterListViewHitTestInfo.ItemSelection</span>.</p>
<p>These two items differ when combined items are turned on (see <strong><em><a href="chapter-items.html#combined-items">Combined Items</a></em></strong> for
more information).</p>
<p>The <span class="code">ItemDisplay</span> property always refers to the displayed
item under cursor regardless of combined items. The
<span class="code">ItemSelection</span> property refers to corresponding selectable
item.</p>
<h2>Sample Source Code</h2>
<p>The following sample shows handler of
<span class="code">BetterListViewHitTestChanged</span> event setting comprehensive
information about hit test in a <span class="code">TextBox</span>:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">private void ListViewHitTestChanged(object sender, BetterListViewHitTestChangedEventArgs eventArgs)
{
BetterListViewHitTestInfo hitTestInfo = eventArgs.HitTestInfoNew;
StringBuilder sbHitTest = new StringBuilder();
sbHitTest.AppendLine(String.Format("Locations: {0}", hitTestInfo.Locations));
if ((hitTestInfo.Locations &amp; BetterListViewHitTestLocations.ColumnHeader) == BetterListViewHitTestLocations.ColumnHeader)
{
sbHitTest.AppendLine();
sbHitTest.AppendLine(String.Format("Column header: '{0}'", hitTestInfo.ColumnHeader.Text));
sbHitTest.AppendLine(String.Format("Column header part: {0}", hitTestInfo.ColumnHeaderPart));
sbHitTest.AppendLine(String.Format("Column header state: {0}", hitTestInfo.ColumnHeaderStateInfo.ColumnHeaderState));
}
if ((hitTestInfo.Locations &amp; BetterListViewHitTestLocations.Group) == BetterListViewHitTestLocations.Group)
{
sbHitTest.AppendLine();
sbHitTest.AppendLine(String.Format("Group: '{0}'", hitTestInfo.Group.Header));
sbHitTest.AppendLine(String.Format("Group part: {0}", hitTestInfo.GroupPart));
sbHitTest.AppendLine(String.Format("Group state: {0}", hitTestInfo.GroupStateInfo.GroupState));
sbHitTest.AppendLine(String.Format("Group expand button state: {0}", hitTestInfo.GroupStateInfo.ExpandButtonState));
}
if ((hitTestInfo.Locations &amp; BetterListViewHitTestLocations.Item) == BetterListViewHitTestLocations.Item)
{
sbHitTest.AppendLine();
sbHitTest.AppendLine(String.Format("Item: '{0}'", hitTestInfo.ItemDisplay.Text));
sbHitTest.AppendLine(String.Format("Item part: {0}", hitTestInfo.ItemPartDisplay));
sbHitTest.AppendLine(String.Format("Item state: {0}", hitTestInfo.ItemStateInfo.ItemState));
}
if ((hitTestInfo.Locations &amp; BetterListViewHitTestLocations.SubItem) == BetterListViewHitTestLocations.SubItem)
{
sbHitTest.AppendLine();
sbHitTest.AppendLine(String.Format("Sub-item: '{0}'", hitTestInfo.SubItem.Text));
sbHitTest.AppendLine(String.Format("Sub-item part: {0}", hitTestInfo.SubItemPart));
}
this.textBoxHitTest.Text = sbHitTest.ToString();
}</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">Private Sub ListViewHitTestChanged (ByVal sender As Object, ByVal eventArgs As BetterListViewHitTestChangedEventArgs)
Dim hitTestInfo As BetterListViewHitTestInfo = eventArgs.HitTestInfoNew
Dim sbHitTest As New StringBuilder()
sbHitTest.AppendLine ([String].Format ("Locations: {0}", hitTestInfo.Locations))
If _
(hitTestInfo.Locations And BetterListViewHitTestLocations.ColumnHeader) =
BetterListViewHitTestLocations.ColumnHeader Then
sbHitTest.AppendLine()
sbHitTest.AppendLine ([String].Format ("Column header: '{0}'", hitTestInfo.ColumnHeader.Text))
sbHitTest.AppendLine ([String].Format ("Column header part: {0}", hitTestInfo.ColumnHeaderPart))
sbHitTest.AppendLine ([String].Format ("Column header state: {0}",
hitTestInfo.ColumnHeaderStateInfo.ColumnHeaderState))
End If
If (hitTestInfo.Locations And BetterListViewHitTestLocations.Group) = BetterListViewHitTestLocations.Group Then
sbHitTest.AppendLine()
sbHitTest.AppendLine ([String].Format ("Group: '{0}'", hitTestInfo.Group.Header))
sbHitTest.AppendLine ([String].Format ("Group part: {0}", hitTestInfo.GroupPart))
sbHitTest.AppendLine ([String].Format ("Group state: {0}", hitTestInfo.GroupStateInfo.GroupState))
sbHitTest.AppendLine ([String].Format ("Group expand button state: {0}",
hitTestInfo.GroupStateInfo.ExpandButtonState))
End If
If (hitTestInfo.Locations And BetterListViewHitTestLocations.Item) = BetterListViewHitTestLocations.Item Then
sbHitTest.AppendLine()
sbHitTest.AppendLine ([String].Format ("Item: '{0}'", hitTestInfo.ItemDisplay.Text))
sbHitTest.AppendLine ([String].Format ("Item part: {0}", hitTestInfo.ItemPartDisplay))
sbHitTest.AppendLine ([String].Format ("Item state: {0}", hitTestInfo.ItemStateInfo.ItemState))
End If
If (hitTestInfo.Locations And BetterListViewHitTestLocations.SubItem) = BetterListViewHitTestLocations.SubItem _
Then
sbHitTest.AppendLine()
sbHitTest.AppendLine ([String].Format ("Sub-item: '{0}'", hitTestInfo.SubItem.Text))
sbHitTest.AppendLine ([String].Format ("Sub-item part: {0}", hitTestInfo.SubItemPart))
End If
TextBoxHitTest.Text = sbHitTest.ToString()
End Sub</code></pre>
<br><div class="banner">
<a href="../../../better-thumbnail-browser.html"><img src="../resources/better-thumbnail-browser-overview.gif" alt="Better Thumbnail Browser" class="ss"></a>
<div class="inside">
<div class="text">Better Thumbnail Browser for .NET (C#, VB) - Image thumbnail viewing and loading control</div>
<span class="dbtn-c dbtn-hilight"><span class="dbtn-w"><a href="../../../betterthumbnailbrowser.exe" class="dbtn">Download</a></span></span>
<span class="dbtn-c"><span class="dbtn-w"><a href="../../../better-thumbnail-browser.html" class="dbtn">More Info</a></span></span>
</div>
</div>
<table class="navigation"><tr>
<td class="navigation-previous"><a href="chapter-groups.html"><strong>
« Groups</strong></a></td>
<td class="navigation-index"><a href="../../../better-thumbnail-browser/documentation.html"><strong>Index</strong></a></td>
<td class="navigation-next"><a href="chapter-insertion-mark.html"><strong>Insertion Mark »
</strong></a></td>
</tr></table>
<br><table class="footer"><tr>
<td class="footer-title">Better Thumbnail Browser Documentation
</td>
<td class="footer-copyright">
Copyright © 2010-2012  <a href="../../../index.html" target="_blank">ComponentOwl.com</a>
</td>
</tr></table>
</div></body>
</html>