使表单在首次加载时不可见 [英] Making a form be invisible when it first loads

查看:108
本文介绍了使表单在首次加载时不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,窗体的不透明度为0%,因此在加载时,它应该是不可见的,但是在加载窗体时,它的可见性将持续几秒钟.由于默认的不透明度设置为0%,并且窗体的可见性设置为false,然后将不透明度设置回100%,所以我认为在我告诉它之前,该窗体应该是不可见的.

Currently, the form's opacity is 0%, so that when it loads, it should be invisible, but when the form loads, it's visible for a few seconds. Since the default opacity is set to 0% and the form's visibility is set to false before it's opacity is set back to 100%, I would think that the form should be invisible until I tell it to.

    public FormMain()
    {
        InitializeComponent();
        this.Visible = false;
        this.Opacity = 1.00;
    }

如何默认使表单不可见?

How can I make my form invisible as a default?

推荐答案

有可能.您必须防止Application类使该窗体可见.您不能修改应用程序,该应用程序已被锁定.但这有效:

It's possible. You have to prevent the Application class from making the form visible. You cannot tinker with Application, that's locked up. But this works:

    protected override void SetVisibleCore(bool value) {
        if (!this.IsHandleCreated) {
            this.CreateHandle();
            value = false;
        }
        base.SetVisibleCore(value);
    }

这是一次性取消,您下次调用Show()或将Visible = true设置为可见.您需要某种触发器,典型的是NotifyIcon上下文菜单.请注意,Load事件在实际可见之前不会运行.其他所有内容都像正常一样工作,调用Close()方法将终止程序.

This is a one-time cancellation, your next call to Show() or setting Visible = true will make it visible. You'd need some kind of trigger, a NotifyIcon context menu is typical. Beware that the Load event won't run until it actually gets visible. Everything else works like normal, calling the Close() method terminates the program.

这篇关于使表单在首次加载时不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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