【问题标题】:TableLayoutpannel, Custom Control, Right ClickTableLayoutpannel,自定义控件,右键
【发布时间】:2014-12-21 21:26:24
【问题描述】:

我有一个由我创建的自定义控件填充的 TableLayoutpannel。

我需要的是当我右键单击自定义控件时如何获取鼠标位置?

我尝试了 MouseUp 事件,但是当我单击自定义控件时,不会引发该事件,而是当我单击没有自定义控件的区域时。

那么人们,当我右键单击 TableLayoutpannel 上的自定义控件时,如何检索鼠标位置?

谢谢。

【问题讨论】:

  • 我猜你的意思是用户控件?他们得到鼠标事件,但在某些情况下,他们可能不得不被那里的其他控件“冒泡”。
  • 如果不出意外,覆盖 wndproc 总是有帮助的。
  • @Plutonix 这是一个在单独项目中创建的用户控件。在另一个项目中,我有一个 TableLayoutPanel 包含该控件的实例
  • @Neolisk : 我使用 VB.net
  • 在 UserControl 中,通过在 Handles 子句之后列出所有控件(或在运行时使用 AddHandler 将它们连接起来),使所有控件触发相同的 MouseDown 事件。然后让 UserControl 引发一个Custom Event,带有 TableLayoutPanel 的表单订阅。

标签: vb.net tablelayoutpanel


【解决方案1】:

使用 MouseDown 事件

Private Sub Form5_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Right Then
        ToolTip1.SetToolTip(Button1, e.Location.ToString)
    End If
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    相关资源
    最近更新 更多