vb.net中动态创建的RichtextBoxes的鼠标离开处理程序 [英] Mouse leave handler for dynamically created RichtextBoxes in vb.net

查看:85
本文介绍了vb.net中动态创建的RichtextBoxes的鼠标离开处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Tab控件中动态添加了一些RichTextBox,现在我想检查鼠标何时进入或离开RichTextBox. iam无法处理鼠标事件,这是我的代码

I add some richtextboxes dynamically in a tabcontrol and now i want to check when mouse enter or leave the richtextboxes. iam unable to handel the mouse events here is my code

For Each rtb As RichTextBox In TabControl1.Controls.OfType(Of RichTextBox)()
    AddHandler rtb.MouseLeave, AddressOf rtb_MouseLeave
Next





Private Sub rtb_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
    frmclose = True
    Label1.Text = "leave"
End Sub




处理Me.MouseLeave仅适用于RichTextBoxes的表单,如何为RichtexBoxes添加Handels




Handles Me.MouseLeave is just for form not for richtextboxes, how to add handels for richtexboxes

推荐答案

请按照以下说明进行操作:
1)创建一个新的"Windows应用程序"项目
2)复制下面的代码
3)将其粘贴在Public Class Form1 ... End Class标签之间

Go through the following instructions:
1) Create new "Windows application" project
2) Copy code below
3) Paste it between Public Class Form1 ... End Class tags

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    CreateTabControlWithRichTextBoxOnEachPage()
End Sub


Private Sub CreateTabControlWithRichTextBoxOnEachPage(Optional ByVal iCountOfPages As Integer = 3)
    Dim tc As TabControl = Nothing, tp As TabPage = Nothing, rtb As RichTextBox = Nothing
    Dim i As Integer = 0

    Try
        tc = New TabControl()
        With tc
            .Parent = Me
            .Dock = DockStyle.Fill
        End With

        For i = 1 To iCountOfPages
            tp = New TabPage
            With tp
                .Name = "TabPage" & i.ToString
                .Text = .Name
            End With
            rtb = New RichTextBox
            With rtb
                .Parent = tp
                .Dock = DockStyle.Fill
                .Name = "RichTextBox" & i.ToString
                AddHandler rtb.MouseEnter, AddressOf rtb_MouseEnter
                AddHandler rtb.MouseLeave, AddressOf rtb_MouseLeave
            End With
            tc.TabPages.Add(tp)
        Next

        Me.Refresh()

    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")

    Finally
        rtb = Nothing
        tp = Nothing
        tc = Nothing

    End Try


End Sub

Private Sub rtb_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
    Me.Text = "MouseEnter event in " & sender.Name
End Sub


Private Sub rtb_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
    Me.Text = "MouseLeave event in " & sender.Name
End Sub



所有控件都在运行时添加.一切都很好!
测试它并尝试在您的应用程序中使用.

有关RichTextBox控件的事件的更多信息:
OnMouseEnter [ ^ ]
OnMouseLeave [ ^ ]



All controls are added in run-time. All working great!
Test it and try to use in your application.

More about events for RichTextBox control:
OnMouseEnter[^]
OnMouseLeave[^]


这篇关于vb.net中动态创建的RichtextBoxes的鼠标离开处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆