2013-08-01 68 views
-1

在我的vb.net窗口应用程序中,我写了一些代码在MouseMove事件中。 当我的应用程序运行并且光标进入我的应用程序时,一个messagebox弹出并在一秒钟内不可见。我无法阅读那里面有什么messagebox.net框架中的未知消息框

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

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 
+1

你试图完成什么?我非常确定,在事件处理程序中使用'Application.DoEvents'的'While'循环(特别是对于像MouseMouve这样经常被**的**)是不是一个好主意。 – Andreas

+0

当光标在我的申请表上时(通过在窗体不透明度上加上0.01),否则窗体将是不可见的(通过从窗体不透明度中推导出0.003)。如果你有更好的主意来完成这个任务。 – Kenta

+0

您确定它是[Message box](http://i.msdn.microsoft.com/dynimg/IC534155.png)而不是[balloon](http://msdn.microsoft.com/en-us /library/windows/desktop/aa511451.aspx)或[tooltip](http://msdn.microsoft.com/en-us/library/windows/desktop/aa511495.aspx)? –

回答

1

MessageBox可能是由于ConfigurationManager.GetSection引发的异常造成的。您必须使用断点来验证这一点,或者将IDE配置为自动中断异常(在Visual Studio 2008中:Debug> Exceptions ...,在Common Language Runtime Exceptions旁边放置复选标记)。


您的事件处理程序中的while循环不会像您所期望的那样执行淡入淡出的动画。您可以使用Timer来完成此操作。另外,如果您将Opacity一直设置为0.0,我相信该表单将无法接收MouseEnter事件。下面是一个在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 
0

我不知道有关messagebox你所谈论的,但因为它使你的应用程序,一旦卡住,因为它引发了第一次如此方法ToolDashboard_MouseMove不应该有这里面while循环它永远不会离开,永远不会继续执行应用程序。相反,您应该在您想要的特定控件上使用mouse entermouse leave事件,如果您没有控件,那么您应该创建一个panel或类似的东西,这些东西不会被用户看到,但是您可以使用事件。

+0

好的..我按照你的说法完成了。但仍然获得相同的MessageBox。即使我自己也不确定那个MessageBox是什么,因为它弹出不到一秒钟,立即变得不可见。我无法阅读那个MessageBox里面有什么。 – Kenta

+0

@Learner你能告诉我你收到消息箱时的情景吗? –

+0

我已经更新了你所说的代码。 此应用程序在窗口的右下角运行。 因此,让我们说适应正在运行,我打开了我的Excel表中的一个,然后这个Excel表重叠我的应用程序窗口。所以下一次,当我的光标移动到右下角时,我的应用程序工作正常,但一个未知的MessageBox弹出并在几秒内隐藏,这是非常恼人的。直到没有窗口与我的应用程序重叠时,MessageBox不会弹出。请帮助我在这。让我知道,如果你需要从我的任何更多的投入.. – Kenta