如何在 Visual C 中拖放按钮
问候...
我正在 .net 框架中的 Visual C++ 中工作,我需要能够在运行时移动一个按钮,以便我用鼠标按住它,然后将其留在所需的位置,换句话说,拖放按钮。
我不需要将其拖放到另一个容器中,但在同一个容器中,例如按钮的父级是 panel1,我想将按钮移动到 panel1 内。
值得一提的是,我希望能够在按钮移动时执行代码,而不是在此之后执行代码,例如,在每次更改按钮后输出按钮的位置。
希望这能让这个想法变得清晰,有什么办法可以实现这一点吗?
提前致谢 :)
Greetings...
I'm working in visual c++ in the .net framework, and I need to be able to move a button in the runtime such that I hold it with the mouse and then leave it in the wanted place, in other words, drag and drop the button.
I don't need to drag and drop it in another container, but in the same container, for example the parent of the button is panel1, I want to move the button inside panel1.
Something important to mention is that I want to be able to perform code while the button is being moved and not after that, for example, outputting the location of the button after every single change on it.
Hopefully that makes the idea clear, is there any way to achieve that?
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您使用的是托管 C++/CLI,或者只是 Visual C++。
对于需要同时运行代码的部分,也许您需要一个额外的线程来让该代码在后台运行。请参阅 ::CreateThread 文档。
在我看来,如果按钮拖动是 CDialog 的成员,则必须手动处理按钮拖动。甚至不允许按钮超出面板的代码(顺便问一下,“面板”是什么意思?它是一个组框吗?)。请参阅
的文档,并且不要忘记将此行添加到消息映射中
I will assume you are using Managed C++/CLI or you simply Visual C++.
For the part that you need to run code at the same time, maybe you will need an extra thread for that code to run in background. See the ::CreateThread documentation.
And seems to me you have to do manually the processing of the button dragging if it is a member of a CDialog. Even the code to not allow the button go ouside the panel (by the way, what you mean with "panel"? Is it a groupbox?) . See documentation for
and do not forget to add this lines to your message map