Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF将处理程序添加到System.Windows.Controls.Label_Wpf_Vb.net_Handler - Fatal编程技术网

WPF将处理程序添加到System.Windows.Controls.Label

WPF将处理程序添加到System.Windows.Controls.Label,wpf,vb.net,handler,Wpf,Vb.net,Handler,我正在尝试向动态创建的Label System.Windows.Controls.Label的MouseLeftButtonUp添加处理程序,但收到一条错误消息 未为“Private Sub btnLink”的参数“e”指定参数Clicked Sender作为对象,e作为MouseButtonEventArgs 如何以编程方式将此事件处理程序添加到标签?一旦我将有更多的标签由同一个函数处理?您将缺少: 在VB.NET中,每次引用方法子或函数而不调用/执行它时,都必须使用AddressOf。例如,

我正在尝试向动态创建的Label System.Windows.Controls.Label的MouseLeftButtonUp添加处理程序,但收到一条错误消息

未为“Private Sub btnLink”的参数“e”指定参数Clicked Sender作为对象,e作为MouseButtonEventArgs

如何以编程方式将此事件处理程序添加到标签?一旦我将有更多的标签由同一个函数处理?

您将缺少:

在VB.NET中,每次引用方法子或函数而不调用/执行它时,都必须使用AddressOf。例如,如果要将其作为参数传递给另一个方法/语句/运算符,或者要将其存储在变量中并在代码中使用

这是必需的,因为AddressOf创建了一个方法的。委托基本上是围绕方法指针的面向对象包装器,这意味着您现在可以像对待.NET中的任何其他对象一样对待它

阅读更多:

Private Sub CreateClickableLabel()

   Dim btnLink As New System.Windows.Controls.Label()

   btnLink.Content = "Click Me"
   AddHandler btnLink.MouseLeftButtonUp, btnLink_Clicked

   Windows.Controls.Grid.SetColumn(btnLink, 0)
   Windows.Controls.Grid.SetRow(btnLink, 0)
   gridData.Children.Add(btnLink)
End Sub


Private Sub btnLink_Clicked(ByVal sender As Object, ByVal e As MouseButtonEventArgs)

   MessageBox.Show("You clicked me")

End Sub
AddHandler btnLink.MouseLeftButtonUp, AddressOf btnLink_Clicked