Hide part of form on load

Posted on 2009-12-16
Last Modified: 2013-11-26
Hi Experts,
I'm sure one of you can tell me a better way to accomplish what I need, but here is what I am trying to do.  Attached is a screen shot of the form I am currently working with.  What I'm trying to do is hide the bottom half of the form.  As you can see from the screen shot, I have my "Bank Information" and "Name On Check" fields inside a panel.  I only want those fields to show if the user clicks on the "Create New Profile" button.  I can accomplish this by hiding the panel when the form loads, but I don't want a big blank empty space for the bottom half of my window.  I can't find anything on how to hide part of a form, so I'm thinking there is a better way.
Question by:isda-don
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    One way is just to grab the bottom of the form and drag it up so the bottom half isn't visible.  When the button is pressed you make the form bigger:

        this.Size = new Size(this.Size.Width, this.Seize.Height + 500); // <-- You need to experiment with what value works best for your form

    Of course, you need to use some kind of variable to track whether or not the form is currently "expanded" so you don't try to expand it more.  To collapse the form just do the opposite and subtract the right amount...
    LVL 29

    Accepted Solution

    Code to use can be very simple.
    I have a panel anchored to the bottom of a form (and to the sides).
    And, for example, a button with the code you may see below:
            bool hidden;
            int panelheight = 184;
            private void button2_Click(object sender, EventArgs e)
                if (!hidden){
                    hidden = true;
                    this.panel1.Height = 0;
                    this.Height = this.Height - panelheight;
                    this.panel1.Height = panelheight;
                       hidden = false;
                    this.Height = this.Height + panelheight;

    Open in new window


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now