Hi
i use this code for hide form but when i run project form is shown !!! where is probleam ???
thanks

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

Dani AI

Generated

Brief recap: tried to hide the form in the Load handler and found the window still appears. was right about timing — the form startup sequence causes the visible window to be created after Load — and 's approach (making the form invisible until after the startup sequence) is a practical fix for that timing.

Why it happens: Load runs while the form is being prepared; the framework completes the show process later (Shown/Activated). Changing Visible in Load can be overridden by the later steps. See the event docs for details: Form.Load and Form.Shown.

A more robust pattern for splash screens is to control startup from Program.Main so the main form is never made visible until initialization finishes. ApplicationContext is handy for this: it lets the app run a splash, perform background work, then create and set the real MainForm when ready. Minimal pattern:

// create and run a custom ApplicationContext that shows a splash,
// performs initialization on a background thread, then replaces it with the main form.
Application.Run(new MySplashApplicationContext());

Notes and cautions: updating UI from background threads requires marshaling (Invoke/BeginInvoke). Showing a splash on a separate UI thread is possible but adds complexity. Overriding SetVisibleCore is another advanced option if you need direct control of initial visibility.

Recommended Answers

All 10 Replies

I think it's because the Form_Load event happens before the form itself is shown, therefore there is nothing to hide. I'm not sure but that's my guess, I don't have a solution for you yet though. I'm sure someone here will come up with something soon.

Hi
i use this code for hide form but when i run project form is shown !!! where is probleam ???
thanks

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

Hello,

Try

this.hide

Or

this.hide()

Cannot remember if it needs the brackets or not.

Hi , i test it but it`s not work too !!!

use

this.hide();

before opening another Form i think then it will work

Apologies,

i forgot to add to the end of the code ;

this.hide();

thanks for pointing that out onlinessp, i'm new myself and still finding it tricky to remember what to type when not in front of the code on my computer.

Try this

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    this.Opacity = 0;
}

protected override void OnShown(EventArgs e)
{
    base.OnShown(e);
    this.Visible = false;
    this.Opacity = 100;
}

Or this if you're not happy with overrides.

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

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

this is my code i do it for show splash

public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Hide();           
            SplashScreen splash = new SplashScreen();
            splash.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Show();
        }
    }

but its not work !!!

The form is shown by the shown event.
Hiding the form before this has no effect as the Show method will override it.
My code uses the forms Opacity property to make the form invisible.
Since you do not actually need to 'hide' your form you can set Opacity to 0 in form load then set is to 100 in your timer event.

private void Form1_Load(object sender, EventArgs e)
        {
            //this.Hide();           
            this.Opacity = 0;
            SplashScreen splash = new SplashScreen();
            splash.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //this.Show();
            this.Opacity = 100;
        }

yes it`s work true , thanks to all

If solved then please mark the thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.