Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Resizing a form the programming way.

C# Resizing a form the programming way.

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hengy
    wrote on last edited by
    #1

    I am developing a serch application. I want to it to have a "Simple" option and an "Advanced" option. When I press the Simple button I want some options to disapear (which I can do) and the form to get smaller (reduce Height only). I need help with code for making the form smaller. I have tried using the MSDN site examples, but Visual Studio 2005 doesn't recognize: Form1.Height = 145 It says I need aditional information (System.Windows. etc.) Hengy I like Pie -- modified at 10:18 Sunday 4th June, 2006 Hengy I like Pie

    L M 2 Replies Last reply
    0
    • H Hengy

      I am developing a serch application. I want to it to have a "Simple" option and an "Advanced" option. When I press the Simple button I want some options to disapear (which I can do) and the form to get smaller (reduce Height only). I need help with code for making the form smaller. I have tried using the MSDN site examples, but Visual Studio 2005 doesn't recognize: Form1.Height = 145 It says I need aditional information (System.Windows. etc.) Hengy I like Pie -- modified at 10:18 Sunday 4th June, 2006 Hengy I like Pie

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What's the exact error message? This works fine:

      this.Height -= 150; // reduce height by 150 pixels
      this.Width += 200; // increase width by 200 pixels
      this.Height = 300; // set height to exactly 300 pixels

      If you want to change these values from outside the form, then you need to replace this with an instance variable of your form, like this:

      Form1 form = new Form1();
      form1.Height = 200;

      regards

      H 1 Reply Last reply
      0
      • L Lost User

        What's the exact error message? This works fine:

        this.Height -= 150; // reduce height by 150 pixels
        this.Width += 200; // increase width by 200 pixels
        this.Height = 300; // set height to exactly 300 pixels

        If you want to change these values from outside the form, then you need to replace this with an instance variable of your form, like this:

        Form1 form = new Form1();
        form1.Height = 200;

        regards

        H Offline
        H Offline
        Hengy
        wrote on last edited by
        #3

        Thanks The second piece of code didn't work, but I played around with it and finally did get it to work. this.Height = 145; Hengy I like Pie

        L 1 Reply Last reply
        0
        • H Hengy

          Thanks The second piece of code didn't work, but I played around with it and finally did get it to work. this.Height = 145; Hengy I like Pie

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You can't directly access the Form1 class and call Height as a static method. You need an instance of your Form1 object, which you already have, namely form

          Form1 form = new Form1(); // create our form
          // ... display it, do other things with it
          form.Height = 200;

          H 1 Reply Last reply
          0
          • L Lost User

            You can't directly access the Form1 class and call Height as a static method. You need an instance of your Form1 object, which you already have, namely form

            Form1 form = new Form1(); // create our form
            // ... display it, do other things with it
            form.Height = 200;

            H Offline
            H Offline
            Hengy
            wrote on last edited by
            #5

            I'm a little lost in what you said... I'm kind of new to C#, but thanks anyways. Hengy I like Pie

            1 Reply Last reply
            0
            • H Hengy

              I am developing a serch application. I want to it to have a "Simple" option and an "Advanced" option. When I press the Simple button I want some options to disapear (which I can do) and the form to get smaller (reduce Height only). I need help with code for making the form smaller. I have tried using the MSDN site examples, but Visual Studio 2005 doesn't recognize: Form1.Height = 145 It says I need aditional information (System.Windows. etc.) Hengy I like Pie -- modified at 10:18 Sunday 4th June, 2006 Hengy I like Pie

              M Offline
              M Offline
              malikjhangirahmed hotmail com
              wrote on last edited by
              #6

              Whenever you need to resize your form, you can reset the size property of your form like this.size=new Size(newWidth,newHeight) As soon as this line will be executed, you form will be resized. Here you can give the height and width whichever you want. But remember, you need to take into consideration the new sizes of your controls on the form since they may not look pretty with the resized form. That's it... Wasif Ehsan.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups