我画出来的组件为什么是个黑框,而不是clear样式的(100)

  • 主题发起人 令狐小侠
  • 开始时间

令狐小侠

Unregistered / Unconfirmed
GUEST, unregistred user!
unit KjGraph;interfaceuses SysUtils, Classes, Controls,windows,messages,graphics;type TZoom = 10..1000; TKjGraph = class(TCustomControl) private FZoom: Tzoom; procedure SetZoom(const Value: Tzoom); { Private declarations } protected procedure WMPaint(var Msg : TWMPaint);message WM_Paint; procedure Paint;override; { Protected declarations } public Constructor Create(AOwner:Tcomponent);override; property Zoom: Tzoom read FZoom write SetZoom default 100; published { Published declarations } end;procedure Register;implementationprocedure Register;begin RegisterComponents('KjGraph', [TKjGraph]);end;{ TKjGraph }constructor TKjGraph.Create(AOwner: Tcomponent);begin inherited;end;procedure TKjGraph.Paint;begin Canvas.Lock; try with Canvas do begin Pen.Style := psDash; Brush.Style := bsClear; Rectangle(0, 0, Width, Height); end; finally Canvas.Unlock; end;end;procedure TKjGraph.SetZoom(const Value: Tzoom);begin FZoom := Value;end;procedure TKjGraph.WMPaint(var Msg: TWMPaint);var DC, MemDC: HDC; MemBitmap, OldBitmap: HBITMAP; PS: TPaintStruct; SavedDC: Integer; Offset: Integer;begin if Msg.DC <> 0 then begin if not (csCustomPaint in ControlState) and (ControlCount = 0) then inherited else PaintHandler(Msg); end else begin // Offset := Zoom div 100; DC := GetDC(0); try MemBitmap := CreateCompatibleBitmap(DC, ClientRect.Right,//Right + HorzScrollBar.Position + Offset, ClientRect.Bottom);//Bottom + VertScrollBar.Position + Offset); finally ReleaseDC(0, DC); end; MemDC := CreateCompatibleDC(0); OldBitmap := SelectObject(MemDC, MemBitmap); try SavedDC := SaveDC(MemDC); try // SetMapMode(MemDC,MM_ANISOTROPIC); //helei 设置坐标映射模式 // SetWindowExtEx(MemDC, 100, 100, nil);// // SetViewPortExtEx(MemDC, Zoom, Zoom, nil); Msg.DC := MemDC; try WMPaint(Msg); finally Msg.DC := 0; end; finally RestoreDC(MemDC, SavedDC); end; DC := BeginPaint(WindowHandle, PS); try BitBlt(DC, 0, 0, ClientRect.Right, ClientRect.Bottom, MemDC, 0, 0, SRCCOPY); finally EndPaint(WindowHandle, PS); end; finally SelectObject(MemDC, OldBitmap); DeleteDC(MemDC); DeleteObject(MemBitmap); end; end;end;end.
 
顶部