이 코드는 Control.GetChildAtPoint와 Control.PointToClient를 모두 사용하여 사용자가 클릭 한 지점에서 정의 된 태그를 사용하여 컨트롤을 재귀 적으로 검색합니다.
private void Form1_HelpRequested(object sender, HelpEventArgs hlpevent)
{
// Existing example code goes here.
// Use the sender parameter to identify the context of the Help request.
// The parameter must be cast to the Control type to get the Tag property.
Control senderControl = sender as Control;
//Recursively search below the sender control for the first control with a Tag defined to use as the help message.
Control controlWithTag = senderControl;
do
{
Point clientPoint = controlWithTag.PointToClient(hlpevent.MousePos);
controlWithTag = controlWithTag.GetChildAtPoint(clientPoint);
} while (controlWithTag != null && string.IsNullOrEmpty(controlWithTag.Tag as string));
// Existing example code goes here.
}
좋은 시작, 감사합니다. HelpEventArgs.MousePos는 마우스 포인터의 화면 좌표를 제공하는 반면 GetChildAtPoint는 "컨트롤의 클라이언트 영역의 왼쪽 위 모퉁이를 기준으로"입니다. 따라서 재귀 적으로 특정 컨트롤을 검색하기 전에 일부 변환을 수행하여 사용 가능한 지점을 가져와야합니다. –