如果有其他人遇到了同样的问题,最终我只是在父控件中添加了一些处理来调用用户控件中的功能:
Form1(void)
{
InitializeComponent();
MouseWheel += gcnew MouseEventHandler(this, &Form1::MouseWheelHandler);
}
void MouseWheelHandler(Object^ sender, MouseEventArgs^ e)
{
m_myUserControl->MouseWheel(e->Delta);
}
获取UserControls的鼠标事件的解决方案是设置控件的背景。每个面板(Grid,Canvas等)都需要背景颜色来处理鼠标事件。
因此,只需为您的控件添加透明背景即可捕获滚动事件。
最初的回答:
Set the Background of your UserControl to transparent to capture mouse events.
Background="Transparent"
OnPaint
事件来进行一些绘图。我已经查看了父级System::Windows::Forms::Form
,但似乎也没有MouseWheel事件。根据你的说法,父级目前会处理这个事件? - Jon CageUserControl
不作为其他控件的容器,而是继承自PictureBox
(或类似控件)? - Rowland Shaw