silverlight 5开发【vb版】(6)-鼠标滚轮事件

本文介绍了一个使用Visual Basic编写的示例程序,演示了如何通过鼠标滚轮事件改变Label控件的内容。该程序还包含了处理鼠标点击和其他鼠标事件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        If e.Delta > 0 Then
            Label3.Content = Label3.Content + 1
        Else
            Label3.Content = Label3.Content - 1
        End If

 e.Delta > 0表示向上滚,否则为向下滚

 

接上节,完整代码如下:

Partial Public Class MainPage
    Inherits UserControl
    Private currentlocation As Point
    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Label1.Content = "您好," & TextBox1.Text & "!"
    End Sub

    Private Sub LayoutRoot_MouseMove(sender As System.Object, e As System.Windows.Input.MouseEventArgs) Handles LayoutRoot.MouseMove
        currentlocation = e.GetPosition(LayoutRoot)
        Label2.Content = "现在鼠标的坐标是:(" & currentlocation.X.ToString() & "," & currentlocation.Y.ToString() & ")"
    End Sub

    Private Sub LayoutRoot_MouseLeftButtonDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs) Handles LayoutRoot.MouseLeftButtonDown
        MessageBox.Show("您按了左键")
    End Sub

    Private Sub LayoutRoot_MouseRightButtonDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs) Handles LayoutRoot.MouseRightButtonDown
        MessageBox.Show("您按了右键")
    End Sub

    Private Sub Label3_MouseWheel(sender As System.Object, e As System.Windows.Input.MouseWheelEventArgs) Handles Label3.MouseWheel
        If e.Delta > 0 Then
            Label3.Content = Label3.Content + 1
        Else
            Label3.Content = Label3.Content - 1
        End If

    End Sub
End Class

 截图如下:



 当鼠标滚轮在label控件中活动时,事件发生,这里的例子是使label控件中的值变大或变小

整个工程代码见附件

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值