• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Alpha混合器可以对TForm进行VCL控制吗

用户头像
it1352
帮助1

问题说明

Alpha Blend可以实现或者对TForm上的VCL控件实现类似的效果?

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

例如,考虑以下屏幕截图,除了其他控件之外,还有两个TPanels放在TForm上。两个面板均可拖动(请参阅 如何移动和调整大小控制在运行时间)。

For example, consider the following screenshot where two TPanels are placed on a TForm in addition to other controls. Both the panels are made draggable (See How to Move and Resize Controls at Run Time).

现在,可以让这些面板在拖动时半透明,以便您可以看到下面的内容? (如通过图像处理产生的第二个图像所示)

Now, is it possible to make these panels translucent while dragging so that you can see what is underneath? (as shown in the second image which was produced by image manipulation)

正确答案

#1

您也可以在Delphi中执行此操作。基本思想是将控件放入自动化的边框形式,并启用Alpha混合。

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

根据您链接的文章,在MouseDown事件中添加以下行:

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;

在MouseMove事件中,设置控件父项的Left和Top属性:

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;

并在MouseUp事件中发布表单,将控件父级设置为原始父级,并将屏幕位置相对于新的位置:

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;

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfhcie
系列文章
更多 icon
同类精品
更多 icon
继续加载