Is it possible to Alpha Blend a VCL control on a TForm?

前端 未结 3 1529
北海茫月
北海茫月 2020-12-14 03:51

Is it possible to Alpha Blend or implement a similar effect for a VCL control on a TForm?

For example, consider the following screenshot where two TPanels are place

3条回答
  •  被撕碎了的回忆
    2020-12-14 04:44

    You can do this in Delphi, too. The basic idea is to place the control into an autosized, borderles form with alpha blending enabled.

    According to the article you linked to, in the MouseDown event add the following lines:

      P := TWinControl(Sender).ClientToScreen(Point(0,0));
      frm := TForm.Create(nil);
      TWinControl(Sender).Parent := frm;
      frm.BorderStyle := bsNone;
      frm.AlphaBlend := true;
      frm.AlphaBlendValue := 128;
      frm.AutoSize := true;
      frm.Left := P.X;
      frm.Top := P.Y;
      frm.Position := poDesigned;
      frm.Show;
    

    In the MouseMove event set the Left and Top properties of the controls parent:

      GetCursorPos(newPos);
    
      Screen.Cursor := crSize;
      Parent.Left := Parent.Left - oldPos.X + newPos.X;
      Parent.Top := Parent.Top - oldPos.Y + newPos.Y;
      oldPos := newPos;
    

    and in the MouseUp event release the form, set the controls parent back to the original parent and translate the screen position to the new position relative to it:

    frm := TWinControl(Sender).Parent;
    P := Point(frm.Left, frm.Top);
    P := ScreenToClient(P);
    TWinControl(Sender).Parent := Self;
    TWinControl(Sender).Left := P.X;
    TWinControl(Sender).Top := P.Y;
    frm.Free;
    Screen.Cursor := crDefault;
    ReleaseCapture;
    inReposition := False;
    

提交回复
热议问题