Delph/Builder 拖放图像,离开控制时图像消失

发布于 2024-08-20 16:48:56 字数 573 浏览 10 评论 0原文

我有一个实现拖放的树控件。我使用重写的 OnStartDrag() 来获取我自己的 TDragObjectEx,它在拖动时显示图像。这在树控件中完美运行,但是一旦我离开树控件,图像就会消失。但光标仍然保留。

我尝试实施 OnDragOver 来重置图像,但这似乎不起作用。

对此有任何提示吗?我正在使用 C++ builder 2010,但 delphi 也会做同样的事情。

更新: 发现在表单控件中的每个控件上设置csDisplayDragImage,并且在表单本身中解决了这个问题。是否有某种自动化方法可以在整个表单中设置 csDisplayDragImage,而不必在“创建”中为每个项目手动设置?

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    ControlStyle << csDisplayDragImage;
    RMU->ControlStyle << csDisplayDragImage;
    Button1->ControlStyle << csDisplayDragImage;
}

I have a tree control that implements drag and drop. I use an overridden OnStartDrag() to get my own TDragObjectEx that shows an image while dragging. This works perfectly within the tree control, but as soon as I leave the tree control the image disappears. The cursor stays though.

I tried implementing OnDragOver, to reset the image but that does not appear to work.

Any hints on this? I am using C++ builder 2010, but delphi would do the same thing.

Update:
Found setting csDisplayDragImage on each control in the form controls, and in form itself solves this issue. Is there some automated way to have csDisplayDragImage set in an entire form rather than have to set it manually in Create for each item?

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    ControlStyle << csDisplayDragImage;
    RMU->ControlStyle << csDisplayDragImage;
    Button1->ControlStyle << csDisplayDragImage;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖凝香 2024-08-27 16:48:56

如果我没记错的话,您必须在您希望在某些情况下看到拖动图像的控件的“ControlStyle”中包含 [csDisplayDragImage] 标志。正在被拖动到它们上方。

更新:设置 DragObject 的“AlwaysShowDragImages”会导致拖动图像在整个桌面上显示。

If I remember correct, you have to include the [csDisplayDragImage] flag in the "ControlStyle" of controls of which you want drag images to be seen when sth. is being dragged over them..

Update: setting "AlwaysShowDragImages" of the DragObject causes the drag image to be displayed all across the desktop.

初熏 2024-08-27 16:48:56

显然,每个要显示拖动图像的控件都需要具有 csDisplayDragImage 控制风格设置。您可以使用一个简单的函数将该标志添加到控件及其所有子控件:

void AddDisplayDragImageStyle(TControl* ctl)
{
  ctl->ControlStyle << csDisplayDragImage;
  TWinControl* win = dynamic_cast<TWinControl*>(ctl);
  if (win)
    for (int i = 0; i < win->ControlCount; ++i)
      AddDisplayDragImageStyle(win->Controls[i]);
}

让表单自行调用该标志:AddDisplayDragImageStyle(this)

Evidently, each control that's going to display the drag image needs to have the csDisplayDragImage control style set. You can add that flag to a control and all its chilren with a simple function:

void AddDisplayDragImageStyle(TControl* ctl)
{
  ctl->ControlStyle << csDisplayDragImage;
  TWinControl* win = dynamic_cast<TWinControl*>(ctl);
  if (win)
    for (int i = 0; i < win->ControlCount; ++i)
      AddDisplayDragImageStyle(win->Controls[i]);
}

Have the form call that on itself: AddDisplayDragImageStyle(this).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文