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. hide and resize controls

hide and resize controls

Scheduled Pinned Locked Moved C#
question
10 Posts 5 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.
  • X Offline
    X Offline
    xrado
    wrote on last edited by
    #1

    im hiding the groupbox and i want to fill the empty space with datagrid that is still visible. how do resize the datagrid to feet the space, is there a easy way?

    M P 2 Replies Last reply
    0
    • X xrado

      im hiding the groupbox and i want to fill the empty space with datagrid that is still visible. how do resize the datagrid to feet the space, is there a easy way?

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      You can simply assign a new Location and Size property to any control to alter its appearance:

      grpBox.Hide();
      dataGrid.Location = grpBox.Location;
      dataGrid.Size = grpBox.Size;

      Regards, mav

      X 1 Reply Last reply
      0
      • M mav northwind

        You can simply assign a new Location and Size property to any control to alter its appearance:

        grpBox.Hide();
        dataGrid.Location = grpBox.Location;
        dataGrid.Size = grpBox.Size;

        Regards, mav

        X Offline
        X Offline
        xrado
        wrote on last edited by
        #3

        i dont understand why 1.) dataGrid1.Size = groupBox3.Size + dataGrid1.Size; work and... 2.) dataGrid1.Size.Height = groupBox3.Size.Height + dataGrid1.Size.Height; dont i wanna change only dataGrid1 Height

        C 1 Reply Last reply
        0
        • X xrado

          i dont understand why 1.) dataGrid1.Size = groupBox3.Size + dataGrid1.Size; work and... 2.) dataGrid1.Size.Height = groupBox3.Size.Height + dataGrid1.Size.Height; dont i wanna change only dataGrid1 Height

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          The Size object is immutable. That means that once created it does not change. You cannot set the Height of a Size object because that would change the object, you have to create a new Size object and use that - which is why your example 1 worked.


          My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

          X 1 Reply Last reply
          0
          • C Colin Angus Mackay

            The Size object is immutable. That means that once created it does not change. You cannot set the Height of a Size object because that would change the object, you have to create a new Size object and use that - which is why your example 1 worked.


            My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

            X Offline
            X Offline
            xrado
            wrote on last edited by
            #5

            can you help me please ...am learning not workink code: groupBox3.Hide(); dataGrid1.Location = groupBox3.Location; dataGrid1.Size.Height = groupBox3.Size.Height + dataGrid1.Size.Height;

            C 1 Reply Last reply
            0
            • X xrado

              can you help me please ...am learning not workink code: groupBox3.Hide(); dataGrid1.Location = groupBox3.Location; dataGrid1.Size.Height = groupBox3.Size.Height + dataGrid1.Size.Height;

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              As I said already: The Size object is immutable. That means that once created it does not change. You cannot set the Height of a Size object because that would change the object, you have to create a new Size object and use that In your code that means the line

              dataGrid1.Size.Height = groupBox3.Size.Height + dataGrid1.Size.Height;

              cannot work because you are attempting to set the Height property on an immutable object. (If the property is on the left hand side [LHS] of the equals operator then that is a set operation, if the property is on the right hand side [RHS] of the equals operator then that is a get operation) So, going back to what I said, you have to create a new Size object. Something like this would work

              Size newSize = new Size(dataGrid1.Size.Width, groupBox3.Size.Height+dataGrid1.Size.Height);
              dataGrid1.Size = newSize;

              By the way, you should really attempt to name your controls (and all variables) with sensible names. groupBox3 and dataGrid1 are not self-explanatory. You will have difficulty in determining what you were trying to do if you come back to look at the code later. Does this help?


              My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

              X 1 Reply Last reply
              0
              • X xrado

                im hiding the groupbox and i want to fill the empty space with datagrid that is still visible. how do resize the datagrid to feet the space, is there a easy way?

                P Offline
                P Offline
                Paul Brower
                wrote on last edited by
                #7

                You could put the groupbox in a panel, and then when you hide the groupbox, set the Dock property of the datagrid to DockStyle.Fill

                X 1 Reply Last reply
                0
                • C Colin Angus Mackay

                  As I said already: The Size object is immutable. That means that once created it does not change. You cannot set the Height of a Size object because that would change the object, you have to create a new Size object and use that In your code that means the line

                  dataGrid1.Size.Height = groupBox3.Size.Height + dataGrid1.Size.Height;

                  cannot work because you are attempting to set the Height property on an immutable object. (If the property is on the left hand side [LHS] of the equals operator then that is a set operation, if the property is on the right hand side [RHS] of the equals operator then that is a get operation) So, going back to what I said, you have to create a new Size object. Something like this would work

                  Size newSize = new Size(dataGrid1.Size.Width, groupBox3.Size.Height+dataGrid1.Size.Height);
                  dataGrid1.Size = newSize;

                  By the way, you should really attempt to name your controls (and all variables) with sensible names. groupBox3 and dataGrid1 are not self-explanatory. You will have difficulty in determining what you were trying to do if you come back to look at the code later. Does this help?


                  My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                  X Offline
                  X Offline
                  xrado
                  wrote on last edited by
                  #8

                  it helps! thx!! :)

                  1 Reply Last reply
                  0
                  • P Paul Brower

                    You could put the groupbox in a panel, and then when you hide the groupbox, set the Dock property of the datagrid to DockStyle.Fill

                    X Offline
                    X Offline
                    xrado
                    wrote on last edited by
                    #9

                    thx for tip!:)

                    M 1 Reply Last reply
                    0
                    • X xrado

                      thx for tip!:)

                      M Offline
                      M Offline
                      MoustafaS
                      wrote on last edited by
                      #10

                      And you may try :

                      dataGrid1.BringToFront();

                      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