ListBox에서 이미지 미리보기
문제
파일 이름의 목록 상자에있는 항목 위에 마우스를 가져갈 때 이미지의 미리보기 (거의 힌트와 같은)를 표시하려면 어떻게해야합니까? 양식을 보여주고 이미지를로드하려고 시도했지만 미리보기 양식이 표시되면 Listbox에 초점을 잃게됩니다. 즉, 마우스를 움직일 때 목록의 다음 항목으로 이동할 때 미리보기 이미지가 변경되지 않습니다. .
고마워요, 피터.
Tondrej의 답변을 바탕으로 사용자 정의 ThintWindow를 구현하려고했지만 Canvas.stretchDraw는 매개 변수로 전송 된 비트 맵을 그립니다. 어떤 아이디어도 그렇지 않습니까? 텍스트는 정상적으로 표시됩니다.
procedure TFormMain.DisplayPreview(HintImage: TBitmap);
var
CustomHint: THintWindow;
Rect: TRect;
MousePoint: TPoint;
begin
*{
Based on Source: http://www.chami.com/tips/delphi/112996D.html
}*
GetCursorPos(MousePoint);
with Rect do
begin
// set the position and size of the hint window
Left := MousePoint.X;
Top := MousePoint.Y;
Right := Left + 50;
Bottom := Top + 25;
end;
CustomHint := THintWindow.Create(Self);
try
with CustomHint do
begin
// set the background color
//Color := clNone;
**Canvas.StretchDraw(Rect, HintImage);**
ActivateHint(Rect, 'Hint');
Application.ProcessMessages;
//
// perform your tasks here
// before closing the hint window
//
Sleep(500);
ReleaseHandle;
end;
finally
if Assigned(CustomHint) then
CustomHint.Free;
end;
end;
해결책
나에게 그것은 당신이 사용자 정의 힌트 창을 원한 것 같습니다. 이렇게하려면 새로운 것을 써야합니다 THintWindow
새 클래스를 HintWindowClass
글로벌 변수 Forms
당신이 처리 할 자신의 Listbox Descendant를 작성하십시오. CM_HINTSHOW
메시지를 보내고 새 힌트 창 클래스를 할당하십시오 HintInfo.HintWindowClass
. (Hintinfo는 당신의 통제로 전달 된 기록을 CM_HINTSHOW
VCL의 메시지)
다른 팁
1) 대화 상자 (모달 창)과 같은 미리보기 양식을 표시 한 다음 비 모달 창으로 변경하십시오.
2) 미리보기 양식이 나타나면 부모의 초점을 다시 설정하는 것을 잊지 말고 ListBox가있는 부모 양식에 초점이 맞고 마우스 이동 이벤트를 ListBox로 전달합니다.
친애하는.