Alpha混合器可以对TForm进行VCL控制吗? [英] Is it possible to Alpha Blend a VCL control on a TForm?

查看:275
本文介绍了Alpha混合器可以对TForm进行VCL控制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

推荐答案

您也可以在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;

这篇关于Alpha混合器可以对TForm进行VCL控制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆