如何在C#桌面应用程序的启动中隐藏窗口? [英] How to hide a window in start in c# desktop application?

查看:263
本文介绍了如何在C#桌面应用程序的启动中隐藏窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个桌面应用程序,该应用程序将被隐藏,但仅在一定时间间隔后才显示。我正在尝试在窗口加载事件时设置Visible = false,但仍显示。

I am trying to make a desktop application that will be hidden but will display only after a time interval. I am trying to set Visible =false at window load event but it still displays.

推荐答案

对于WinForms应用程序,我发现控制启动可见性的最简单方法是覆盖 SetVisbileCore 方法。

For WinForms applications I have found that the easiest way to control the start-up visibility is to override the SetVisbileCore method.

这是一个简单的示例,表单将在5秒钟后显示

Here is a simple example, the form will show after 5 seconds

using System;
using System.Windows.Forms;

namespace DelayedShow
{
  public partial class Form1 : Form
  {
    private bool _canShow = false;
    private Timer _timer;

    public Form1()
    {
      InitializeComponent();
      _timer = new Timer();
      _timer.Interval = 5000;
      _timer.Tick += new EventHandler(timer_Tick);
      _timer.Enabled = true;
    }

    void timer_Tick(object sender, EventArgs e)
    {
      _canShow = true;
      Visible = true;
    }

    protected override void SetVisibleCore(bool value)
    {
      if (_canShow)
      {
        base.SetVisibleCore(value);
      }
      else
      {
        base.SetVisibleCore(false);
      }
    }
  }
}

这篇关于如何在C#桌面应用程序的启动中隐藏窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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