2009-07-27 14 views
1

Delphi 2009에서 컨트롤에 "포커스 rect"를 그릴 수있는 옵션이 있습니까?컨트롤에서 포커스 rect 제거 - Delphi

-Pavan.

+2

을 시도 할 수 있다면 나는이 오래된 질문이다 알지만? 관련된 세부 사항으로 더 나은 답변을 얻을 수 있습니다. – Argalatyr

답변

2

이 문제에 대한 해결책은 컨트롤의 상속에 따라 다릅니다. 일부는 Paint 메서드를 재정의해야하며 다른 일부는 ownerdraw가 필요합니다. 나는 일반적인 해결책을 모른다.

일부 Raize components에는 false로 설정할 수있는 ShowFocusRect 속성이 있습니다. 이는 잘 만들어진 구성 요소의 장점 중 하나입니다.

초점 사각형이 표준 Windows 사용자 인터페이스의 일부라고 주장하는 사람이 있습니다 (관련 토론은 here입니다). 어떤 상황에서는 행동을 재정의하기위한 경우가있을 것이라고 확신합니다.

0

다음은 this newsgroup post의 ownerdraw를 사용하여 StringGrid에서 초점 사각형을 표시하지 않는 예입니다. Paint 메서드에서 포커스 사각형이 그려지는 컨트롤에서는이 옵션이 작동하지 않습니다. false로 그리기

설정의 기본은 OnDrawCell 이벤트에이 첨부 :

procedure TMiscForm.StringGrid1DrawCell(Sender: TObject; 
      ACol, ARow: Integer; 
      Rect : TRect; 
      State : TGridDrawState); 
var 
    SG: TStringGrid; 
begin 
    if Sender is TStringGrid then 
    begin 
    SG:= TStringGrid(Sender); 
    SG.Canvas.Font:= SG.Font; 
    SG.Canvas.Brush.Color:= SG.Color; 
    SG.Canvas.Brush.Style:= bsSolid; 

    if gdFixed in State then 
     SG.Canvas.Brush.Color:= SG.FixedColor; 

    if (gdSelected in State) and not (gdFocused in State) then 
    begin 
     SG.Canvas.Brush.Color:= clHighLight; 
     SG.Canvas.Font.color := clHighLightText; 
    end; 

    SG.Canvas.Pen.Color := SG.Canvas.Brush.Color; 
    SG.Canvas.Pen.Mode := pmCopy; 
    SG.Canvas.Pen.Style := psSolid; 
    SG.Canvas.Pen.Width := 1; 
    SG.Canvas.Rectangle(Rect); 

    if SG.Canvas.Ctl3D and (gdFixed in State) then 
    begin 
     if goFixedVertLine in SG.Options then 
     begin 
     SG.Canvas.Pen.Color := clBtnHighLight; 
     MoveTo(Rect.Left, Rect.Bottom-1); 
     LineTo(Rect.Left, Rect.Top); 
     SG.Canvas.Pen.Color := clBtnShadow; 
     MoveTo(Rect.Right-1, Rect.Top); 
     if goFixedHorzLine in SG.Options then 
      LineTo(Rect.Right-1, Rect.Bottom) 
     else LineTo(Rect.Right-1, Rect.Bottom+SG.GridLineWidth); 
     end; 

     if goFixedHorzLine in SG.Options then 
     begin 
     SG.Canvas.Pen.Color := clBtnHighLight; 
     MoveTo(Rect.Left, Rect.Top); 
     LineTo(Rect.Right, Rect.Top); 
     SG.Canvas.Pen.Color := clBtnShadow; 
     if goFixedVertLine in SG.Options then 
     begin 
      MoveTo(Rect.Left+1, Rect.Bottom-1); 
      LineTo(Rect.Right, Rect.Bottom-1) 
     end 
     else 
     begin 
      MoveTo(Rect.Left, Rect.Bottom-1); 
      LineTo(Rect.Right + SG.GridLineWidth, Rect.Bottom-1); 
     end; 
     end; 
    end; 

    SG.Canvas.Brush.Style:= bsClear; 
    TextRect(Rect, Rect.Left + 2, Rect.Top + 2, SG.Cells[ACol,ARow]); 

    SG.Canvas.Brush.Style:= bsSolid; 
    if gdFocused in State then 
     SG.Canvas.DrawFocusRect(Rect); 
    end; 
end; 
0

을 스틸 관심을 항상 제어

procedure TfrmPic.MyStringGridDrawCell(Sender: TObject; 
    ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); 
begin 
    // Deliberately draw focus rectangle which is subsequently redrawn; 
    if gdSelected in State then 
    MyStringGrid.Canvas.DrawFocusRect(Rect); 
end; { procedure TfrmPic.sgCorDrawCell } 
+0

일반적으로 작동합니까? OP는 해당 객체의 상속을 지정하지 않았습니다. – Argalatyr

관련 문제