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. Adapting form size to content size

Adapting form size to content size

Scheduled Pinned Locked Moved C#
csharpvisual-studiocomhelptutorial
5 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.
  • S Offline
    S Offline
    sinosoidal
    wrote on last edited by
    #1

    Hi, I have a preview form for several type of contents. I want to adapt the form size to the contents size dynamicly. For example, I have a mediaPlayer COM named mpPreview. I tried to do this: this.Size.Height = mpPreview.Size.Height; But it gives me the following error: Error 1 Cannot modify the return value of 'System.Windows.Forms.Form.Size' because it is not a variable D:\Os meus documentos\Visual Studio\Coordinator\Preview.cs 78 13 Coordinator Why? Thx, Nuno

    O A 3 Replies Last reply
    0
    • S sinosoidal

      Hi, I have a preview form for several type of contents. I want to adapt the form size to the contents size dynamicly. For example, I have a mediaPlayer COM named mpPreview. I tried to do this: this.Size.Height = mpPreview.Size.Height; But it gives me the following error: Error 1 Cannot modify the return value of 'System.Windows.Forms.Form.Size' because it is not a variable D:\Os meus documentos\Visual Studio\Coordinator\Preview.cs 78 13 Coordinator Why? Thx, Nuno

      O Offline
      O Offline
      Obaid ur Rehman
      wrote on last edited by
      #2

      Try using this: this.Size = new Size(this.Size.Width, mpPreview.Size.Height);

      1 Reply Last reply
      0
      • S sinosoidal

        Hi, I have a preview form for several type of contents. I want to adapt the form size to the contents size dynamicly. For example, I have a mediaPlayer COM named mpPreview. I tried to do this: this.Size.Height = mpPreview.Size.Height; But it gives me the following error: Error 1 Cannot modify the return value of 'System.Windows.Forms.Form.Size' because it is not a variable D:\Os meus documentos\Visual Studio\Coordinator\Preview.cs 78 13 Coordinator Why? Thx, Nuno

        A Offline
        A Offline
        Arjun Mjolnir Bahree
        wrote on last edited by
        #3

        To understand the reason why C# prevents you from doing this, you need to understand the basics of value types (or structures). Unlike reference types, when value types are returned from methods (or set via an assignment), a copy of the value type is returned and not the orginal version. In the situation above, Form.Size is a property (which is a method underneath) and it returns the Size value type. So when you attempt to assign a value to Size.Height, you are actually attempting to assign it to a copy and not the underlying Size structure. Although, it is technically valid to do this, the C# compiler makes the assumption that this is not what you want to do, and hence fires the compiler error.

        Excelsior Arjun Bahree "By The Might of Mjolnir" I Came! I Coded! I Conquered!

        1 Reply Last reply
        0
        • S sinosoidal

          Hi, I have a preview form for several type of contents. I want to adapt the form size to the contents size dynamicly. For example, I have a mediaPlayer COM named mpPreview. I tried to do this: this.Size.Height = mpPreview.Size.Height; But it gives me the following error: Error 1 Cannot modify the return value of 'System.Windows.Forms.Form.Size' because it is not a variable D:\Os meus documentos\Visual Studio\Coordinator\Preview.cs 78 13 Coordinator Why? Thx, Nuno

          A Offline
          A Offline
          Arjun Mjolnir Bahree
          wrote on last edited by
          #4

          Use a this.Height instead of this.Size.Height and it will work.

          Excelsior Arjun Bahree "By The Might of Mjolnir" I Came! I Coded! I Conquered!

          S 1 Reply Last reply
          0
          • A Arjun Mjolnir Bahree

            Use a this.Height instead of this.Size.Height and it will work.

            Excelsior Arjun Bahree "By The Might of Mjolnir" I Came! I Coded! I Conquered!

            S Offline
            S Offline
            sinosoidal
            wrote on last edited by
            #5

            Thx guys! This effort for now was useless. My content isnt resizing, so i cannot see this working. Basicly i have three kind of elements in this form: - web browser - media player - picture box I want this form to popup when i click previw in a list of element of several file types. For now i'm just focusing in videos. I want my media player to resize to current video's size. Is there any easy way of doing that, without having to see the movies information in order to get its size? Thx, Nuno

            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