0

使用 flash 时,我可以通过访问事件的“目标”属性来获得事件的焦点。

所以如果我记得,它是类似的东西。

button1.addEventListener(mouse_click, doSomething);

doSomething(e: Event){
    e.target.size = 50000;
}

我正在寻找 VB 中的等价物。

如果您能给我它在所有语言中的通用名称,我将不胜感激。除了“event.target VB.net 等价物”之外,我不太清楚要搜索什么,这并没有返回任何内容。

提前致谢。

编辑:对于那些新来闪光的人。我所说的焦点是指被点击的物理对象。因此,给出的示例将访问单击按钮的大小。

4

2 回答 2

1

在 VB 中,您可以使用 WithEvents 关键字声明性地连接事件处理程序,或者使用 AddHandler 强制连接事件处理程序。

Private WithEvents myButton

' OR

Public Sub New
  Dim newButton = New Button()
  AddHandler newButton.Click, AddressOf MyClickHandler
End New

'To consume it you declare a method as follows:
' The Handles clause is used when declaring WithEvents
Private Sub MyClickHandler(sender As Object, e As EventArgs) Handles myButton.Click
  ' The sender has a handle on the object that raised the event (aka the button)
  Dim btn = DirectCast(sender, Button)
  btn.Size = New Size(500, 500)

End Sub
于 2012-09-14T16:16:54.990 回答
0

知道了!

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclick.aspx#Y0

    Sub GreetingBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
        'When the button is clicked,
        'change the button text, and disable it.

        Dim clickedButton As Button = sender
        clickedButton.Text = "...button clicked..."
        clickedButton.Enabled = False
    End Sub

第一个参数(默认为 sender)引用焦点对象。您可以像访问任何其他普通变量一样访问它,但它的信息不会出现在自动完成列表中,除非您将其设置为“作为”该特定数据类型。

所以我结束了这个

    Private Sub nw_btn_Click(ByVal sender As System.Windows.Forms.Button, ByVal e AsSystem.EventArgs) Handles nw_btn.Click
        sender.Hide()
    End Sub
于 2012-09-14T16:26:26.363 回答