C# Winforms 用户控件拖动并捕捉到面板(运行时)
我正在尝试编写一个程序来管理我的团队的任务。为此,我使用具有拖放功能的自定义UserControls
。我尝试以下操作:当将 UserControl
拖动到插槽
上时,该控件应该捕捉到插槽
中。问题似乎是插槽没有获取诸如 "MouseEnter"
或 "DragEnter"
之类的事件。有谁知道解决方法,或者是否可以将事件传递下去?
我想我只需要朝着正确的方向一点推动。
编辑:
主要功能: 用户控件(我们称之为任务
)在释放时应停靠在槽
中。 slot
由属性和面板组成。该任务应该出现在面板中。
奖金: 任务
在拖动时应停靠在不同的槽
中。这样当“任务”被释放时它所在的位置总是可见的。
我希望这表明我正在努力做的事情。
编辑2 澄清一下:我使用“MouseDown”、“MouseUp”和“MouseMove”进行拖放。
在这里您可以看到我的示例,蓝色面板是我的任务。它应该卡入的白色插槽。
在第二张图片上,我将任务拖到插槽面板上。鼠标在这里不可见,但它就在任务“K”旁边。
来测试以下代码。如果引发事件,则应将插槽内的面板着色为某种颜色。但颜色保持白色。
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
this.panel1.BackColor = Color.Black;
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
this.panel1.BackColor = Color.Green;
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Yellow;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Violet;
}
为什么我在老虎机面板上看不到事件? 我希望这有助于理解我的问题。
I am trying to write a program to manage tasks from my team. For this I use drag&drop capable custom UserControls
. I try the following: When the UserControl
is dragged over a slot
, the control should then snapped into the slot
. The problem seems to be that the slot does not get the events like "MouseEnter"
or "DragEnter"
. Does anyone know a workaround, or is it possible to pass events down?
I think I just need a little push in the right direction.
Edit:
Main functionality:
The user control, let's call it task
, should be docked into a slot
when released over it.
A slot
consists of properties and a panel. The task should appear in the panel.
Bonus:
A task
, should dock into the different slots
while dragging. So that it is always visible where the 'task' is placed when it is released.
I hope this shows what I am trying to do.
Edit 2
To clarification: I use the "MouseDown", "MouseUp" and "MouseMove" for the drag an drop.
Here you can see my Example the blueish panel is my task. The white the slot it should snap to.
On the second picture I drag the Task over the Slot panel. The mouse is not visable here but it's right beside the "K" of task.
i have added for testing the following code. Which should color the panel inside the slot in a color if an event is raised. But the color stays white.
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
this.panel1.BackColor = Color.Black;
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
this.panel1.BackColor = Color.Green;
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Yellow;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Violet;
}
Why I don't get events on the Slotpanel?
I hope that this helps to understand my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论