c#winform窗体加载后隐藏 写到加载事件中隐藏错误,如何解决?

2025-04-06 19:08:07
推荐回答(2个)
回答1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
              // 不能在这里隐藏窗体!因为Load事件是在加载窗体以及窗体控件时发生的。
              // 这时,窗体没有还没完成加载和显示
              // 如果此时设置窗体不可见则可能没有效果,或者出错
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            //在这里隐藏窗体!当窗体激活(Activated)时,窗体已经加载完毕了
            this.Hide(); 
        }
    }
}

回答2:

贴代码来看看