Adapting form size to content size
-
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
-
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
Try using this:
this.Size = new Size(this.Size.Width, mpPreview.Size.Height);
-
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
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!
-
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
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!
-
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!
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