使用Alt + Tab时Showdialog消失

时间:2019-02-28 00:22:40

标签: vb.net showdialog

我有一个MDI容器,而且我使用了自己的自定义类MsgBox(称为ShowMsg),该类主要在子窗体上使用,到目前为止,它工作得很好,直到我意识到Showmsg(这是一个ShowDialog)没有坚持到父表单(MDIContainer)。

在子窗体中,如果用户在进程运行并完成时使用alt + tab切换到另一个程序,并且用户使用Alt +返回到我的应用程序,则我使用线程来运行进程并显示进度栏Tab,ShowMsg不在那里,它消失了,我无能为力,无法恢复它,所以我的应用程序变得无用了。

仅当从与Form本身不同的线程中调用它时,才会发生这种情况,我正在拔头发,为什么消失了??

这是代码的一部分:


parser.add_argument('infile', metavar="INFILE", nargs='?',
                    type=argparse.FileType('r'),
                    action='append', dest="positional_args")
parser.add_argument('outfile', metavar="OUTFILE", nargs='?', 
                    type=argparse.FileType('w'),
                    action='append', dest="positional_args")
parser.add_argument('-i', metavar="INFILE", dest="infile", default=None)
parser.add_argument('-o', metavar="OUTFILE", dest="outfile", default=None)

args = parser.parse_args([....])

# here insert check for conflicts between len(args.positional_args) and -i and -o
# example:
if sum([len(args.positional_args),
       args.infile is not None,
       args.outfile is not None]) != 2:
   parser.print_help()
   sys.exit(1)
...

infile = args.infile or args.positional_args.pop(0)
outfile = args.outfile or args.positional_args.pop(0)

在孩子身上的样本:

Public Function ShowMsg(ByVal Text As String, ByVal Icon As ShowMsgImage, ByVal Title As String) As DialogResult
    Dim SMF As New ShowMsgForm

    'Set the title bar
    SMF.Text = Title

    'Select an image and sound based on the Icon parameter
    Select Case Icon
        Case ShowMsgImage.Alert
            SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Warning
            SMF.Sound = Media.SystemSounds.Asterisk
        Case ShowMsgImage.Confirm
            SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Confirm
            SMF.Sound = Media.SystemSounds.Question
        Case ShowMsgImage.Critical
            SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_NotAllowed
            SMF.Sound = Media.SystemSounds.Hand
        Case ShowMsgImage.Info
            SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Info
            SMF.Sound = Media.SystemSounds.Asterisk
        Case ShowMsgImage.Security
            SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Lock
            SMF.Sound = Media.SystemSounds.Beep
        Case ShowMsgImage.UnderConstruction
            SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_NotAllowed
            SMF.Sound = Media.SystemSounds.Asterisk
        Case ShowMsgImage.Ok
            SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_ok
            SMF.Sound = Media.SystemSounds.Asterisk
    End Select

    'Set other properties
    SMF.TextLabel.Text = Text
    SMF.QuestionTextLabel.Text = ""
    SMF.Button1.Visible = True
    SMF.Button1.Text = "OK"
    SMF.Button1.DialogResult = DialogResult.OK
    SMF.Button2.Visible = False
    SMF.Button3.Visible = False

    'Resize the form
    SMF.SizeForm()

    'Set its starting position
    SMF.StartPosition = FormStartPosition.CenterScreen

    'Display the form modally and return its DialogResult
    Try
        Return SMF.ShowDialog()
    Catch ex As Exception

    End Try


End Function

1 个答案:

答案 0 :(得分:0)

经过几天的测试,我认为我找到了答案。

我添加了:

  • TopLevel = True,显示时
  • 参数父母表格

            SMF.TopLevel = True
            Return SMF.ShowDialog(**frm**)
    

frm是调用ShowMsg的形式