请问如何画出类似TCanvas.DrawFocusRect效果焦点矩形一样的框线,即点空点的虚线,但不会像DrawFocusRect一样是XOR的,再调用一次即擦除
因为我调用的时候是不知道以前是否已经调用过一次DrawFocusRect,所以不管以前是不是调用过,调用后的效果都要求像第一次调用一样的效果,即总是显示,而不擦除.
效果图:
procedure TForm1.btn1Click(Sender: TObject);
var
  MyRect: TRect;
begin
  MyRect := Rect(20,20, 180,100);
  Canvas.DrawFocusRect(MyRect);
  //第二次调用时就被擦除了
end;

解决方案 »

  1.   


    var
      MyRect: TRect;
    begin
      MyRect := Rect(20,20, 180,100);
      Canvas.Pen.Style:=psDashDotDot;
      Canvas.Rectangle(MyRect);
    end;
      

  2.   


    //Dot间隔比较大
    var
      MyRect: TRect;
    begin
      Canvas.Pen.Style := psDot;
      MyRect := Rect(20,20,180,00);
      Canvas.Rectangle(MyRect);
    end;
      

  3.   

    加些逻辑判断就可以了,这样,第一次画了之后,你再怎么点都显示那个框  pubilc
         IsDraw : Boolean;
      end;procedure TForm1.btn1Click(Sender: TObject);
      var MyRect : TRect;
    begin
      MyRect := Rect(50,50,250,150);
      if not IsDraw then
      begin
        Form1.Canvas.DrawFocusRect(MyRect);
        IsDraw := True;
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      IsDraw := False;
    end;
      

  4.   


    加逻辑变量判断的方法不是没考虑过,不过因为是要把画的功能封装成一个黑盒的函数,所以是无法实现像你代码那样函数体里和函数外的逻辑变量运行交互的.(当然,如果你能写出逻辑变量在函数体内的代码另当别论~就你的代码,IsDraw 放在TForm1.btn1Click里,这基本不可能吧?)
      

  5.   

    最好的方法是 自己画Because DrawFocusRect is an XOR function, calling it a second time with the same rectangle removes the rectangle from the screen. This function draws a rectangle that cannot be scrolled. To scroll an area containing a rectangle drawn by this function, call DrawFocusRect to remove the rectangle from the screen, scroll the area, and then call DrawFocusRect again to draw the rectangle in the new position. 根据这说明,如果你画的部分正好有重叠的已经画其他颜色,那么会出现画的黑点并不是黑色.
      

  6.   

    似乎听过以前文章用ExtCreatePen可以画出点虚线,只是不知如何使用,请教各位  
      

  7.   

    我写的一个,楼主试下procedure TForm1.Button3Click(Sender: TObject);
    var
      Tb: tagLOGBRUSH;
      Lbr: tagLOGBRUSH;
      NewH, OldH: HGDIOBJ;  procedure Test(b: TPenStyle; aColor: TColor; w: integer);
      begin
        Tb.lbStyle := BS_SOLID;
        tb.lbColor := aColor;
        tb.lbHatch := HS_BDIAGONAL;
        NewH := ExtCreatePen(PS_GEOMETRIC or PS_ENDCAP_FLAT or PS_JOIN_ROUND or PS_DOT, W, tb, 0, nil);
        OldH := SelectObject(Canvas.Handle, NewH);
      end;begin
      Test(psSolid, clBlack, 1);
      MoveToEx(Canvas.Handle, 20, 20, nil);
      LineTo(Canvas.Handle, 180, 20);
      LineTo(Canvas.Handle, 180, 100);
      LineTo(Canvas.Handle, 20, 100);
      LineTo(Canvas.Handle, 20, 20);
      SelectObject(Canvas.Handle, OldH);
      DeleteObject(NewH);
    end;