0

如果创建一个字典程序。当使用在剪贴板上复制一些文本时,它将以系统尝试可见的形式给出复制文本的含义。当用户单击他/她屏幕上的任何位置时,我想关闭表单。但是如果用户想从不关闭的含义中复制一些文本,我会在选项卡控件中添加一个动态创建的丰富文本框以显示含义的数量。当用户滚动richtextboxes 表单时,我的代码运行良好,接受一件事会自行关闭。滚动条似乎不是richtextbox的一部分。帮我解决这个问题,我的代码如下。

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

==更新==

我有 form1,其中包含此代码以将richtextboxes 和选项卡添加到 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)

最后打开frmdict来表示意思

If frmdict.TabControl1.TabPages.Count > 0 Then
  frmdict.TabControl1.RightToLeftLayout = True
  frmdict.Show()
  frmdict.Label1.Focus()
  ' frmdict.TabControl1.Focus()
Else
  frmdict.Close()
End If
4

1 回答 1

0

每当鼠标移过表单的其中一个子控件时,您MouseLeave就会触发,这可能不是您所期望的。

我不确定你的标签和按钮发生了什么,但这样的事情可能会让它对你有用:

If s = True Then
  If Not rtb1.Bounds.Contains(Me.PointToClient(Cursor.Position)) AndAlso _
     TypeOf Me.ActiveControl Is Label Then
    Me.Close()
  End If
End If

更新:

就您的动态富文本控件而言,您实际上并不需要名称。像这样的东西应该可以工作(未完全测试):

If TabControl1.SelectedTab IsNot Nothing Then
  For Each rtb As RichTextBox In TabControl1.SelectedTab.Controls.OfType(Of RichTextBox)()
    If Not rtb.Bounds.Contains(rtb.PointToClient(Cursor.Position)) Then
      Me.Close()
    End If
  Next
End If
于 2012-05-08T16:23:59.897 回答