.net框架中的未知消息框

时间:2013-08-01 05:53:37

标签: .net vb.net winforms

在我的vb.net windows应用程序中,我在MouseMove事件中编写了一些代码。 当我的应用程序运行并且光标进入我的应用程序时,会弹出一个messagebox并在一秒钟内不可见。我无法阅读messagebox内部的内容。

任何人都可以帮助我摆脱这个带有标题.net框架的不必要的messagebox。 这是我的代码

Public Class ToolDashboard
    Imports System.Configuration
    Imports System.Collections.Specialized
    Public Class CompassToolDashboard
    Dim path As NameValueCollection

        Private Sub ToolDashboard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - (Me.Width - 50), Screen.PrimaryScreen.WorkingArea.Height - Me.Height)
            path = ConfigurationManager.GetSection("ToolPath")
        End Sub

         Private Sub ToolDashboard_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
              Me.BringToFront()
              While Me.Opacity < 1
                 Me.Opacity = Me.Opacity + 0.06
             End While
        End Sub

       Private Sub ToolDashboard_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
             While Me.Opacity > 0
                Me.Opacity = Me.Opacity - 0.001
             End While
       End Sub    
       Private Sub CloseForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseForm.Click, CloseForm.Click
            Process.GetCurrentProcess().Kill()
        End Sub

        Private Sub ShareTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VMDashboard.Click
            System.Diagnostics.Process.Start(path("IndexGenerator")) 
        'getting path for Indexgenerator.exe from app.config                 
        'Index generator.exe is present in a remote system      
        End Sub
 End Class

2 个答案:

答案 0 :(得分:1)

MessageBox可能是ConfigurationManager.GetSection引发的异常造成的。您必须使用断点验证这一点,或者配置IDE以自动中断异常(在Visual Studio 2008中:调试&gt;例外...,在公共语言运行时异常旁边放置一个复选标记)。


事件处理程序中的while循环不会像您期望的那样执行渐弱的动画。您可以使用Timer执行此操作。另外,如果您将MouseEnter一直设置为0.0,我相信该表单将无法接收Opacity个事件。这是一个在0.3和1.0之间消失的例子:

Private WithEvents timer As New Timer()
Private visible As Boolean

Public Sub New()
    InitializeComponent()
    timer.Interval = 1
    Opacity = 0.3
End Sub

Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
    visible = True
    timer.Start()
    MyBase.OnMouseEnter(e)
End Sub

Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
    visible = False
    timer.Start()
    MyBase.OnMouseLeave(e)
End Sub

Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer.Tick
    If (visible) Then
        If (Opacity < 0.94) Then
            Opacity += 0.06
        Else
            Opacity = 1.0
            timer.Stop()
        End If
    Else
        If (Opacity > 0.31) Then
            Opacity -= 0.01
        Else
            Opacity = 0.3
            timer.Stop()
        End If
    End If
End Sub

答案 1 :(得分:0)

我不确定您正在谈论的messagebox但是方法ToolDashboard_MouseMove不应该在内部循环,因为它会在第一次触发时使您的应用程序停滞不前所以永远不会离开,永远不会继续申请。相反,你应该在你想要的特定控件上使用mouse entermouse leave事件,如果你没有控制权,你应该创建一个panel或类似的东西,这将是用户不会看到,但您可以使用这些事件。