问题描述
我编写了一个应用程序来帮助发布我们的内部系统(压缩,设置发布信息等).一切正常,除了我有些奇怪的行为.
当MsgBox弹出并显示"Rollout Success"时,如果单击确定"按钮,则该应用程序将从屏幕上消失(如向后移动),并且另一个应用程序将成为焦点.有时,应用程序也会从Windows任务栏上消失(尽管可以按Alt + Tab组合键,如果最小化其他窗口也可以看到).
我还注意到这是在我们的主应用程序中发生的(这是一个MDI父对象,名为DlgForm.ShowDialog(Me).我什至尝试将Me.Activate放在后面以尝试重新获得焦点),但不知道为什么会发生,甚至如何调试它.我以前从未遇到过MsgBox的问题.
有人知道为什么会这样吗?或有关如何解决它的任何想法?
I have written an application to aid releasing our internal systems (compressing, setting release information etc.). Everything works fine, except I get some odd behaviour.
When the MsgBox pops up saying "Rollout Successful", if you click the OK button, the application disappears from the screen (as in moves to the back), and a different application takes focus. Sometimes the application disappears from the Windows taskbar too (though can be Alt+Tabbed to, and visible if you minimise the other windows)
I''ve also noticed this happening inside our main application (It''s an MDI parent calling DlgForm.ShowDialog(Me). I''ve even tried putting Me.Activate afterwards to try and recapture focus), but have no idea why it happens or even how to debug it. I never used to have this issues with MsgBox.
Does anybody know why this happens? or any ideas on how to fix it?
Private Sub ReleaseApp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReleaseApp.Click
Dim res As Assembly
If ReleaseType.Text = "" Then
MsgBox("No reason for release selected")
Exit Sub
End If
Try
res = BuildRolloutAssembly()
If res Is Nothing Then Throw New Exception("Could not create assembly")
Dim relObj As Object = res.CreateInstance("ReleaseObject")
Dim t As Type = res.GetType("ReleaseObject")
If CBool(t.InvokeMember("Release", BindingFlags.InvokeMethod, Nothing, relObj, New Object() {NewVersion.Text, RelNotes.Text, resourceFolder, ReleaseType.Text}, Nothing, Nothing, Nothing)) Then
MsgBox("Rollout Successful", MsgBoxStyle.Information)
Else
MsgBox("Rollout Failed!", MsgBoxStyle.Exclamation)
End If
Catch ex As Exception
MsgBox("Rollout Failed!", MsgBoxStyle.Exclamation)
End Try
End Sub
如果我使用以下内容创建一个新项目:
If I create a new project with the following:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Hello")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MessageBox.Show("Hello 2")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim x As New Form1
x.ShowDialog()
End Sub
End Class
无论您按下哪个按钮,该应用程序都不会失去焦点.这将表明是其他原因导致了此行为.
The application never loses the focus, regardless of which buttons you press. This would indicate that something else is causing this behaviour
推荐答案
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As _
Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As _
Long) As Long
这篇关于MsgBox之后切换应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!