2012-08-12 2 views
4

격자가 다른 모달이 아닌 양식에 포커스를 잃을 때 Delphi XE2에서 StringGrid의 InPlaceEditor의 강조 표시를 유지하는 방법이 있습니까? 내가 초점을 잃은 후 현재 셀의 하이라이트를 보존하기 위해 아래의 코드를 사용하기를 희망했다포커스를 잃을 때 InPlaceEditor 강조 표시 유지

enter image description here

그렇지 않으면, 그러나 떠나 몇 가지 문제가 있어요 :

나의 현재 StringGrid 옵션은 셀은 더 이상 현재 셀이 아닐 때 강조 표시됩니다.

비 선택된 셀의 색상을 원래대로 되돌리려면 아래 코드에 "else"를 추가해야합니까? 어떤주의 사항?

procedure TForm1.sgMultiDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);  
    begin 
    if (ACol = sgMulti.Col) and (ARow = sgMulti.Row) then 
    begin 
     sgMulti.Canvas.Brush.Color := clYellow; 
     sgMulti.Canvas.FillRect(Rect); 
     sgMulti.Canvas.TextRect(Rect, Rect.Left, Rect.Top, sgMulti.Cells[ACol, ARow]); 
     if gdFocused in State then 
     sgMulti.Canvas.DrawFocusRect(Rect); user 
    end; 
    end; { sgMultiDrawCell} 

편집 : 아래의 화면 캡처는 어떻게 작동하는지 보여줍니다. 초점을 잃고 아래 화면 캡처보다 더 명확하게 할 때 나는

enter image description here

+0

@tlama : 내 목표는 포커스를 잃을 때 셀이 어떤 식 으로든 강조 표시되는 것입니다. 내가 말한대로 InPlaceEditor를 편집 모드로 남겨 두었다는 것을 알지 못했습니다. InPlaceEditor를 사용하는 것이 가능하거나 선호하지 않을 것 같아서 이제는 그렇게 할 것입니다. 어쩌면 초점을 맞추지 않은 상태에서 강조 표시해야할까요? (초점이 맞지 않을 때 하이라이트가 편집 모드 하이라이트와 다른 경우 괜찮습니다.) – RobertFrank

+1

'goAlwaysShowEditor' 옵션을 제거하려 했습니까? – kludg

+1

@Serg와 TLama : 나는 네가 옳다고 생각한다. goAlwaysShowEditor를 제거하면 특히 goEditing이 켜져 있기 때문에 제가 원하는 것입니다. 하이라이트를 더 밝게 만들기 위해 goAlwaysShowEditor를 설정하는 것이 좋습니다. 하이라이트 된 테두리 상자 나 색상을 향상시키는 것이 얼마나 힘들겠습니까? Serg : 답변으로 이전 의견을 게시하십시오. 둘 다 감사합니다. – RobertFrank

답변

6

그냥 항상 표시 편집기를 활성화 goAlwaysShowEditor 옵션을 유지하고 강조하려는 경우에 대한 액세스를 필요로 현재 셀에 원하는 InplaceEditor 속성 이렇게하려면 문자열 격자 클래스를 서브 클래스 화하고 inplace 편집기의 색을 변경해야합니다. 기본값은 TCustomMaskEdit입니다. 이 코드에서
는 문자열 그리드
이 집중되는 경우에 여부 따라 인플레 이스 에디터의 색상을 변경하는 방법과 같습니다

type 
    TStringGrid = class(Grids.TStringGrid) 
    private 
    procedure CMEnter(var Message: TCMEnter); message CM_ENTER; 
    procedure CMExit(var Message: TCMExit); message CM_EXIT; 
    protected 
    function CreateEditor: TInplaceEdit; override; 
    end; 

implementation 

{ TStringGrid } 

procedure TStringGrid.CMEnter(var Message: TCMEnter); 
begin 
    inherited; 
    if Assigned(InplaceEditor) then 
    TMaskEdit(InplaceEditor).Color := $0000FFBF; 
end; 

procedure TStringGrid.CMExit(var Message: TCMExit); 
begin 
    inherited; 
    if Assigned(InplaceEditor) then 
    TMaskEdit(InplaceEditor).Color := $0000A6FF; 
end; 

function TStringGrid.CreateEditor: TInplaceEdit; 
begin 
    Result := inherited; 
    if Focused then 
    TMaskEdit(Result).Color := $0000FFBF 
    else 
    TMaskEdit(Result).Color := $0000A6FF; 
end; 

그리고 집중과 산만 그리드 상태 결과 :

enter image description here

+2

와우! 정확히 내가하려는 일. 고마워, @ 라마! – RobertFrank

+1

도와 줘서 기쁩니다 ;-) – TLama

관련 문제