델파이 : 테디가 언제 크기를 바꾸는시기를 아는 방법?
문제
크기가 변경 될 때 편집 상자 주위에 항목을 업데이트해야합니다.
테 디트에는 없다 onresize 이벤트.
편집 상자는 다양한 시간에 크기를 조정할 수 있습니다.
- 코드의 너비/높이 변경
- DPI 스케일링을 위해 조정 된 형태
- 글꼴이 변경되었습니다
그리고 나는 내가 모르는 다른 사람들을 확신합니다.
편집 상자가 크기를 변경했을 때를 알기 위해 단일 이벤트가 필요합니다. 편집 상자를 서브 클래스하고 잡을 수있는 Windows 메시지가 있습니까?
해결책
Onresize는 TControl의 보호 자산으로 선언됩니다. 소위 "크래커"클래스를 사용하여 노출 할 수 있습니다. 그래도 약간의 해킹입니다.
type
TControlCracker = class(TControl);
...
procedure TForm1.FormCreate(Sender: TObject);
begin
TControlCracker(Edit1).OnResize := MyEditResize;
end;
procedure TForm1.MyEditResize(Sender: TObject);
begin
Memo1.Lines.Add(IntToStr(Edit1.Width));
end;
다른 팁
다음과 같은 것을 시도 했습니까?
unit _MM_Copy_Buffer_;
interface
type
TMyEdit = class(TCustomEdit)
protected
procedure Resize; override;
end;
implementation
procedure TMyEdit.Resize;
begin
inherited;
if not (csLoading in ComponentState) then
begin
// react on new size
end;
end;
end.
아니면 이거:
unit _MM_Copy_Buffer_;
interface
type
TCustomComboEdit = class(TCustomMaskEdit)
private
procedure WMSize(var Message: TWMSize); message WM_SIZE;
end;
implementation
procedure TCustomComboEdit.WMSize(var Message: TWMSize);
begin
inherited;
if not (csLoading in ComponentState) then
begin
// react on new size
end;
UpdateBtnBounds;
end;
end.
처리 wm_Size
메시지. 새 값을 자사에 할당하여 컨트롤을 서브 클래스 WindowProc
재산; 다른 메시지를 위임 할 수 있도록 이전 값을 저장하십시오.
또한보십시오: wm_WindowPosChanged
제휴하지 않습니다 StackOverflow