procedure TControl.InvalidateControl(IsVisible, IsOpaque: Boolean); var Rect: TRect;
function BackgroundClipped: Boolean; var R: TRect; List: TList; I: Integer; C: TControl; begin Result := True; List := FParent.FControls; I := List.IndexOf(Self); while I > 0 do begin Dec(I); // 这里!为什么是DEC函数?只比较了一小部分兄弟图形控件?但是FControls的内部元素应该是无序的,应该全部比较才对,所以这样写让我觉得无法理解。 C := List[I]; with C do if C.Visible and (csOpaque in ControlStyle) then begin IntersectRect(R, Rect, BoundsRect); if EqualRect(R, Rect) then Exit; end; end; Result := False; end;
begin if (IsVisible or (csDesigning in ComponentState) and not (csNoDesignVisible in ControlStyle)) and (Parent <> nil) and Parent.HandleAllocated then begin Rect := BoundsRect; InvalidateRect(Parent.Handle, @Rect, not (IsOpaque or (csOpaque in Parent.ControlStyle) or BackgroundClipped)); // 这里! end; end;
========== procedure TWinControl.PaintHandler(var Message: TWMPaint); var I, Clip, SaveIndex: Integer; DC: HDC; PS: TPaintStruct; begin DC := Message.DC; if DC = 0 then DC := BeginPaint(Handle, PS); try if FControls = nil then PaintWindow(DC) else // 没有图形子控件直接自绘 begin SaveIndex := SaveDC(DC); Clip := SimpleRegion; for I := 0 to FControls.Count - 1 do // 这里 with TControl(FControls[I]) do if (Visible or (csDesigning in ComponentState) and not (csNoDesignVisible in ControlStyle)) and (csOpaque in ControlStyle) then begin Clip := ExcludeClipRect(DC, Left, Top, Left + Width, Top + Height); if Clip = NullRegion then Break; end; if Clip <> NullRegion then PaintWindow(DC); RestoreDC(DC, SaveIndex); end; PaintControls(DC, nil); finally if Message.DC = 0 then EndPaint(Handle, PS); end; end;
而FControl的背景透明控制完全是通过csOpaque来得到的, 所以你应该会发现 if (Visible or (csDesigning in ComponentState) and not (csNoDesignVisible in ControlStyle)) and (csOpaque in ControlStyle) then 这里只减去了重绘背景的Control
----------------------------------------------
http://www.cnblogs.com/lzl_17948876/
干脆,继续厚着脸皮提问,我注意到TControl.InvalidateControl函数里,第三个参数的第二种条件: InvalidateRect(Parent.Handle, @Rect, not (IsOpaque or (csOpaque in Parent.ControlStyle) or BackgroundClipped)); 即 csOpaque in Parent.ControlStyle; 有什么意义,什么情况下会出现这种情况(这个条件会成立)? 我查了一下,整个Forms单元里都没有用到csOpaque。如果一个TForm是“透明”的,那它代表了什么含义呢?
----------------------------------------------
只有偏执狂才能生存!