if creating a dictionary program. when use copy some text on clipboard it will give the meanings of copied text in a form visible on system try. i want to close the form when user click any where on his/her screen. but if user want to copy some text from meanings from will not close i added more then one dynamically created richtextboxes in a tab control to show number of meanings. my code is working great accept one thing when user scroll the richtextboxes form will close itself. it seems scrollbars are not the part of richtextbox. Help me to solve this problem my code is below.
Dim s As Boolean = True
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If MouseButtons.ToString = "Left" Or MouseButtons.ToString = "Right" Then
If s = True Then
If InStr(LCase(Me.ActiveControl.ToString), LCase("Label")) Then
Me.Close()
End If
End If
End If
End Sub
Private Sub Label1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Label1.Click
Me.Close()
End Sub
Private Sub frmdict_MouseEnter(ByVal sender As Object, ByVal e As EventArgs) Handles Me.MouseEnter
s = False
Button1.Focus()
End Sub
Private Sub frmdict_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles Me.MouseLeave
s = True
Label1.Focus()
End Sub
==Update==
i have form1 which contains this code to add richtextboxes and tabs to tabcontrl
Dim myTabPage As New TabPage()
Dim myrichtext As New RichTextBox()
myrichtext.Name = "RichTextBox" & i
myTabPage.Text = StrSearch & i
frmdict.TabControl1.TabPages.Add(myTabPage)
myTabPage.Controls.Add(myrichtext)
myrichtext.RightToLeft = Windows.Forms.RightToLeft.No
myrichtext.Dock = DockStyle.Fill
myrichtext.Font = New Font("Urdulink", 14)
And finally open frmdict to show meaning
If frmdict.TabControl1.TabPages.Count > 0 Then
frmdict.TabControl1.RightToLeftLayout = True
frmdict.Show()
frmdict.Label1.Focus()
' frmdict.TabControl1.Focus()
Else
frmdict.Close()
End If
Your
MouseLeavedoes fire whenever the mouse goes over one of the child controls of the form, which is probably not what you were expecting.I’m not sure what’s going on with your label and button, but something like this will probably make it work for you:
Update:
In terms of your dynamic rich text controls, you don’t really need the name. Something like this should work (not completely tested):