2009-03-13 6 views
2

Delphi 2007의 TCustomComboBox를 기반으로 사용자 정의 컨트롤을 만들려고하지만 첫 번째 장애물에 붙어 있습니다.Delphi에서 TCustomComboBox 자손 만들기

드롭 다운이 표시되는 방식을 재정의하려고합니다. 기본적으로 표시되는 텍스트는 stdctrls.pas의 TCustomComboBox 소스를보고 DrawItem을 재정의해야하지만 작동하지 않습니다. 내 재정의 된 메서드의 코드는 실행되지 않습니다.

나는 오픈 소스 구성 요소 소스 코드를 보았지만 어떻게 작동하는지 보았다. 그러나 나는 아직도 손해보고있다. 여기

는 지금까지 (별로 인정 하듯이)가 무엇

type 
    TKeyValueComboBox = class(TCustomComboBox) 
    private 
    { Private declarations } 
    //FColumns:Integer; 
    protected 
    { Protected declarations } 
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);override; 
    public 
    { Public declarations } 
    constructor Create(AOwner: TComponent); override; 
    destructor Destroy; override; 
    published 
end; 

그리고

procedure TKeyValueComboBox.DrawItem(Index: Integer; Rect: TRect; 
    State: TOwnerDrawState); 
begin 
    TControlCanvas(Canvas).UpdateTextFlags; 
    if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State) 
    else 
    begin 
    Canvas.FillRect(Rect); 
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]+'-HELLO'); 
    end; 
end; 

사람이 내가 화재의 내 오버라이드 (override) 버전을 얻기 위해 사용하는 데 필요한 방법을 알고 있나요? 또는 내가 뭘 잘못하고있는거야?

도움을 주시면 감사하겠습니다.

답변

5

메모리에서 설정해야하는 속성도 있습니다. DrawingStyle : = dsCustomDraw 생성자에 넣거나로드했습니다.

1

소유자 드로잉을 사용하셨습니까? 기본적으로 비활성화됩니다. 표준 콤보 상자로 사용자 지정 그리기 작업을 얻은 다음 나중에 필요한 모든 설정을 적용하여 사용자 지정 컨트롤을 만듭니다.