THIS.VISIBLE是不是在Windows窗体工作 [英] this.Visible is not working in Windows Forms

查看:255
本文介绍了THIS.VISIBLE是不是在Windows窗体工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我需要隐藏我的窗口在窗口负荷。但

I have a problem. I need to hide my window at window load. But

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Visible = false;
    }

不工作。和财产可见仍是如此。我缺少的东西吗?

is not working. And property Visible remains true. Am I missing something?

推荐答案

是的,Visible属性是一个大问题在Windows窗体,这就是实际获取创建的句柄,并导致的OnLoad()来运行。换言之,不存在窗口,直到它得到可见。它会忽略尝试撤消此。

Yes, the Visible property is a big deal in Windows Forms, that's what actually gets the handle created and causes OnLoad() to run. In other words, the window doesn't exist until it gets visible. And it will ignore attempts to undo this.

这是pretty共同想还是创建手柄,但不能使该窗口可见,如果你使用的NotifyIcon。您可以通过覆盖SetVisibleCore实现这一点:

It is pretty common to want to still create the handle but not make the window visible if you use a NotifyIcon. You can achieve this by overriding SetVisibleCore:

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

当心的OnLoad仍然不能运行,直到窗口实际上得到可见,所以如果需要移动code到构造。只要打电话展()中的NotifyIcon的上下文菜单事件处理程序,以使窗口可见。

Beware that OnLoad still won't run until the window actually gets visible so move code into the constructor if necessary. Just call Show() in the NotifyIcon's context menu event handler to make the window visible.

这篇关于THIS.VISIBLE是不是在Windows窗体工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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