Delphi 代碼實現窗口透明+圓角邊框

procedure TfrmRemoteData.DoInvisible;  //透明
var
  control: TControl;
  index, margin, X, Y, ctlX, ctlY, i: Integer;
  fullRgn, clientRgn, ctlRgn: THandle;
begin
  margin := (Width - ClientWidth) div 2;
  fullRgn := CreateRectRgn(0, 0, Width, Height); //創建總裁剪區域
  X := margin;
  Y := Height - ClientHeight - margin;
  clientRgn := CreateRectRgn(X, Y, X + ClientWidth, Y + ClientHeight);
  CombineRgn(fullRgn, fullRgn, clientRgn, RGN_DIFF); //合併區域,RGN_DIFF差集

  for index := 0 to ControlCount - 1 do   //遍歷控件
  begin
    control := Controls[index];
    if (control is TWinControl) or (control is TGraphicControl) then
      with control do
      begin
        if Visible then
        begin
          ctlX := X + Left;
          ctlY := Y + Top;
//          ctlRgn := CreateRectRgn(CtlX, CtlY, CtlX + Width, CtlY + Height);
          ctlRgn := CreateRoundRectRgn(ctlX, ctlY, ctlX+ Width, ctlY + Height, Height, Height);
          CombineRgn(fullRgn, fullRgn, ctlRgn, RGN_OR);  //RGN_OR並集

        end;
      end;
  end;
  SetWindowRgn(Handle, fullRgn, True);    //設置重繪窗口
end;
說明:CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, arc1, arc2);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章