表单加载时如何隐藏表单. [英] How to hide the form when the form loads.

查看:113
本文介绍了表单加载时如何隐藏表单.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

For Each arg As String In Environment.GetCommandLineArgs()
    If arg.ToLower = "-tray" Then
        Me.Hide()
        MsgBox("You have run -tray")
    End If
Next 



上面的代码不起作用.

"-Tray"的运行方式为虽然工作是我.隐藏事件",

表单未隐藏.

我像一个C:\ Users \ Owner \ Documents \ Visual Studio 2005 \ Projects \ CommandStart \ bin \ Debug \ CommandStart.exe -tray一样运行.

我看到了MsgBox.
但是,表单不是隐藏的.



我该怎么办?



The above code does not work.

''-Tray'' run as Although the work Me.Hide events,

Form is not hidden.

I runned like a ''C:\Users\Owner\Documents\Visual Studio 2005\Projects\CommandStart\bin\Debug\CommandStart.exe -tray''.

I saw the MsgBox is shown.
But, form is not hidden.



How Can I Do?

推荐答案

在实际显示表单之前,您可能运行得太早了.因此,它是隐藏的,然后在窗体加载时仍然由事件序列显示.我会尝试加载事件,如果不起作用,请寻找一个在首次显示表单时触发的事件.
You are probably running this code too early, before the form is actually shown. So, it''s hidden, then it''s still shown by the sequence of events when the form loads. I''d try to Load event and if that does not work, look for an event that fires when the form is first shown.


我该怎么办?

如果事件运行得如此之快,我不知道如何解决.

我创建并遇到了另一个Sub,但是,它仍然没有用.
What do I do?

If the event run so fast, I do not know how to solve it.

I create and run into another Sub, But, It still dosen''t work.


您不应该按"answer"问更多问题.您也许应该买一本有关winforms的书.您的表单会生成事件.当某些事情在表单的生命周期中发生时,它们就会发生.在框架显示表单之前,您正在运行此代码.您的代码需要在框架显示表单之后运行.因此,您需要确定正确的事件来运行代码,以实现此目的.我认为Load事件是一个很好的起点.
You should not press ''answer'' to ask more questions. You should perhaps buy a book on winforms. Your form generates events. They occur when certain things happen in the lifecycle of your form. You are running this code before the form is shown by the framework. Your code needs to run AFTER the framework shows the form. So you need to work out the right event to run your code in, for this to happen. I think the Load event is a good place to start.


这篇关于表单加载时如何隐藏表单.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆