1

我想检测鼠标光标何时在表单上(在表单上意味着在表单上以及在表单的任何控件上以及在航空边框上),然后如果鼠标在整个“表单”上,则更改图片框的背景,当鼠标不在窗体(客户端+非客户端区域)上时,再次更改图片。

这是一个例子:

鼠标移到:

在此处输入图像描述

鼠标离开:

在此处输入图像描述

我试过这样做,但没有办法......:

Private Sub Form1_MouseHover(sender As Object, e As EventArgs) Handles _
    Me.MouseHover, _
    PictureBox_Color.MouseHover, _
    Label_HEX.MouseHover, _
    Label_HEX_Value.MouseHover, _
    Label_HTML.MouseHover, _
    Label_HTML_Value.MouseHover, _
    Label_RGB.MouseHover, _
    Label_RGB_Value.MouseHover, _
    Label_CTRL_C.MouseHover, _
    Label_CTRL_S.MouseHover, _
    Label_CTRL_X.MouseHover, _
    RadioButton_HEX.MouseHover, _
    RadioButton_HTML.MouseHover, _
    RadioButton_RGB.MouseHover, _
    CheckBox_Copy_Syntax.MouseHover, _
    Panel1.MouseHover

    Timer1.Stop()
    Label_RGB_Value.Text = "0"
    Label_HEX_Value.Text = "0"
    Label_HTML_Value.Text = "0"
    PictureBox_Color.BackgroundImage = My.Resources.Elektro
End Sub


Private Sub Form1_MouseLeave(sender As Object, e As EventArgs) Handles _
    Me.MouseLeave, _
    PictureBox_Color.MouseLeave, _
    Label_HEX.MouseLeave, _
    Label_HEX_Value.MouseLeave, _
    Label_HTML.MouseLeave, _
    Label_HTML_Value.MouseLeave, _
    Label_RGB.MouseLeave, _
    Label_RGB_Value.MouseLeave, _
    Label_CTRL_C.MouseLeave, _
    Label_CTRL_S.MouseLeave, _
    Label_CTRL_X.MouseLeave, _
    RadioButton_HEX.MouseLeave, _
    RadioButton_HTML.MouseLeave, _
    RadioButton_RGB.MouseLeave, _
    CheckBox_Copy_Syntax.MouseLeave, _
    Panel1.MouseLeave

    If ((MousePosition.X < Me.Location.X) Or MousePosition.X > (Me.Location.X + Me.Width)) _
    AndAlso ((MousePosition.Y < Me.Location.Y) Or MousePosition.Y > (Me.Location.Y + Me.Height)) Then
        Timer1.Start()
        PictureBox_Color.BackgroundImage = Nothing
    End If

End Sub
4

2 回答 2

0

您可以使用未选择的图像作为 from 的支持,并在图像上使用鼠标,如果一直拉伸到应该工作的表单上。如果我错了请纠正我

于 2013-05-03T14:08:49.810 回答
0

尝试这个;

鼠标移到

Private Sub Button1_MouseHover(sender As Object, e As EventArgs) Handles Button1.MouseHover
    Button1.BackColor = Color.DodgerBlue
End Sub

鼠标离开

Private Sub Button1_MouseLeave(sender As Object, e As EventArgs) Handles Button1.MouseLeave
    Button1.BackColor = Color.Red
End Sub
于 2015-05-19T21:42:37.003 回答