| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
How to: Use Hit Testing with a Region |
03/30/2017 |
.net-framework |
|
article |
|
|
3a4c07cb-a40a-4d14-ad35-008f531910a8 |
14 |
dotnet-bot |
dotnetcontent |
wpickett |
How to: Use Hit Testing with a Region
The purpose of hit testing is to determine whether the cursor is over a given object, such as an icon or a button.
Example
The following example creates a plus-shaped region by forming the union of two rectangular regions. Assume that the variable point holds the location of the most recent click. The code checks to see whether point is in the plus-shaped region. If the point is in the region (a hit), the region is filled with an opaque red brush. Otherwise, the region is filled with a semitransparent red brush.
[!code-csharpSystem.Drawing.MiscLegacyTopics#31] [!code-vbSystem.Drawing.MiscLegacyTopics#31]
Compiling the Code
The preceding example is designed for use with Windows Forms, and it requires xref:System.Windows.Forms.PaintEventArgs e, which is a parameter of xref:System.Windows.Forms.PaintEventHandler.
See Also
xref:System.Drawing.Region
Regions in GDI+
How to: Use Clipping with a Region