다음을 통해 공유


지역을 사용한 적중 테스트

적중 횟수 테스트의 목적은 커서가 아이콘 또는 단추와 같은 지정된 개체 위에 있는지 여부를 확인하는 것입니다. 다음 예제에서는 두 사각형 영역의 공용 구조체를 형성하여 더하기 모양의 영역을 만듭니다. 변수 지점에 최근 클릭 위치가 있다고 가정합니다. 코드는 이 더하기 모양의 영역에 있는지 확인합니다. 이 지역(적중)에 있는 경우 영역은 불투명한 빨간색 브러시로 채워집니다. 그렇지 않으면 영역이 반투명 빨간색 브러시로 채워집니다.

Point point(60, 10);
// Assume that the variable "point" contains the location
// of the most recent click.
// To simulate a hit, assign (60, 10) to point.
// To simulate a miss, assign (0, 0) to point.
SolidBrush solidBrush(Color());
Region region1(Rect(50, 0, 50, 150));
Region region2(Rect(0, 50, 150, 50));
// Create a plus-shaped region by forming the union of region1 and region2.
// The union replaces region1.
region1.Union(&region2);
if(region1.IsVisible(point, &graphics))
{
   // The point is in the region. Use an opaque brush.
   solidBrush.SetColor(Color(255, 255, 0, 0));
}
else
{
   // The point is not in the region. Use a semitransparent brush.
   solidBrush.SetColor(Color(64, 255, 0, 0));
}
graphics.FillRegion(&solidBrush, &region1);