zoukankan      html  css  js  c++  java
  • 什么是透明(和Windows主题有关系),研究TLable和TPanel是两个好例子

    在controls.pas单元里只有判断,没有赋值,所以一直不是很明白。于是在stdCtrls.pas里找了几个例子,直观加深一下印象:

    constructor TCustomLabel.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      ControlStyle := ControlStyle + [csReplicatable];
      Width := 65;
      Height := 17;
      FAutoSize := True;
      FShowAccelChar := True;
      { The "default" value for the Transparent property depends on
        if you have Themes available and enabled or not. If you have
        ever explicitly set it, that will override the default value. }
      if ThemeServices.ThemesEnabled then
        ControlStyle := ControlStyle - [csOpaque]
      else
        ControlStyle := ControlStyle + [csOpaque]; // 默认走这里
    end;
    
    function TCustomLabel.GetTransparent: Boolean;
    begin
      Result := not (csOpaque in ControlStyle);
    end;
    
    procedure TCustomLabel.SetTransparent(Value: Boolean);
    begin
      if Transparent <> Value then
      begin
        if Value then
          ControlStyle := ControlStyle - [csOpaque] 
        else
          ControlStyle := ControlStyle + [csOpaque];
        Invalidate;
      end;
      FTransparentSet := True;
    end;
    
    constructor TCustomListBox.Create(AOwner: TComponent);
    const
      ListBoxStyle = [csSetCaption, csDoubleClicks, csOpaque];
    begin
      inherited Create(AOwner);
      if NewStyleControls then
        ControlStyle := ListBoxStyle else
        ControlStyle := ListBoxStyle + [csFramed];
      Width := 121;
      Height := 97;
      TabStop := True;
      ParentColor := False;
      FAutoComplete := True;
      FItems := TListBoxStrings.Create;
      TListBoxStrings(FItems).ListBox := Self;
      FCanvas := TControlCanvas.Create;
      TControlCanvas(FCanvas).Control := Self;
      FItemHeight := 16;
      FBorderStyle := bsSingle;
      FExtendedSelect := True;
      FOldCount := -1;
    end;

    再在ExtCtrls.pas里找几个素材:

    procedure TImage.PictureChanged(Sender: TObject);
    var
      G: TGraphic;
      D : TRect;
    begin
      if AutoSize and (Picture.Width > 0) and (Picture.Height > 0) then
        SetBounds(Left, Top, Picture.Width, Picture.Height);
      G := Picture.Graphic;
      if G <> nil then
      begin
        if not ((G is TMetaFile) or (G is TIcon)) then
          G.Transparent := FTransparent;
            D := DestRect;
        if (not G.Transparent) and (D.Left <= 0) and (D.Top <= 0) and
           (D.Right >= Width) and (D.Bottom >= Height) then
          ControlStyle := ControlStyle + [csOpaque]
        else  // picture might not cover entire clientrect
          ControlStyle := ControlStyle - [csOpaque];
        if DoPaletteChange and FDrawing then Update;
      end
      else ControlStyle := ControlStyle - [csOpaque];
      if not FDrawing then Invalidate;
    end;
    
    constructor TCustomPanel.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
        csSetCaption, csOpaque, csDoubleClicks, csReplicatable];
      { When themes are on in an application default to making
        TCustomPanel's paint with their ParentBackground }
      if ThemeServices.ThemesEnabled then
        ControlStyle := ControlStyle + [csParentBackground] - [csOpaque];
      Width := 185;
      Height := 41;
      FAlignment := taCenter;
      BevelOuter := bvRaised;
      BevelWidth := 1;
      FBorderStyle := bsNone;
      Color := clBtnFace;
      FFullRepaint := True;
      UseDockManager := True;
    end;
    
    procedure TCustomPanel.SetParentBackground(Value: Boolean);
    begin
      { TCustomPanel needs to not have csOpaque when painting
        with the ParentBackground in Themed applications }
      if Value then
        ControlStyle := ControlStyle - [csOpaque]
      else
        ControlStyle := ControlStyle + [csOpaque];
      FParentBackgroundSet := True;
      inherited;
    end;
  • 相关阅读:
    [CocosCreator]-06-文字渲染
    [CocosCreator]-05-图片渲染
    [CocosCreator]-04-使用对象池
    [CocosCreator]-03-使用计时器
    [CocosCreator]-02-设备重力传感事件
    [CocosCreator]-01-键盘事件
    [h5棋牌项目]-08-请安装所需的版本的 Windows SDK 或者在项目属性页的问题解决方案
    JS规则 较量较量(比较操作符) 两个操作数通过比较操作符进行比较,得到值为真(true)和假(false)。【>; <; >=; <=; !=;==】
    JS规则 自加一,自减一 ( ++和- -) 【mynum = mynum + 1;//等同于mynum++;】
    JS规则 我还有其它用途( +号操作符)例如,算术操作符(+、-、*、/等),比较操作符(<、>、>=、<=等),逻辑操作符(&&、||、!)
  • 原文地址:https://www.cnblogs.com/findumars/p/5185087.html
Copyright © 2011-2022 走看看