473,383 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

textBox1.Size.Width


Why can't the following work when it has a set property defined?
this.textBox1.Size.Width = 25;

I get error

Cannot modify the return value of 'System.Windows.Forms.Control.Size'
because it is not a variable

but following works

Size s = new Size(textBox1.Size.Width + 5, textBox1.Size.Height);
this.textBox1.Size = s;

What is the sence in giving comment for properties get and set?
Documentation error maybe?

Dec 9 '05 #1
5 6629
> Documentation error maybe?
No, the documetation is correct. The property allows you to get and set
the size, that is, the Size structure as a whole.
If you are curious why you get such behavior, think about the fact that
Size is a value type object.

Dec 9 '05 #2
Well I got it now that Size is actually a struct which make sence for it to
throw that error. But still I disagree with the way Size.Width etc are
having comments. It gives a false idea what it is a property.
"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Documentation error maybe?

No, the documetation is correct. The property allows you to get and set
the size, that is, the Size structure as a whole.
If you are curious why you get such behavior, think about the fact that
Size is a value type object.

Dec 9 '05 #3
Sorry, but I don't think you do "get" it; the following works fine:

Size size = new Size();
size.Height = 100;
size.Width = 100;
new Form().Size = size;

So the setters and getters are perfectly valid. The problem is that you are
expecting Size to behave like a class...

Essentially, by typing

textbox1.Size.Width = 100;

You are essentially (in terms of thinking about it) doing the following:

Size tempSize = (Size) textbox1.Size.MemberwiseClone(); // protected
method - substitute with any method that clones this one! I don't know what
method the IL will actually use, but this suffices for the example...
tempSize.Width = 100;

As you can see, we have not altered the size of textbox1 at all, since
textbox1 has a completely different Size object that is unaffected.

The complier has neatly saved you from making this error. You could argue
that it should have updated the Size property with the new struct, but that
would make it very inefficient if you were using this method to update
multiple properties. In this scenario it's better to make you get a local
copy, update the properties on your local copy of the struct, and then
update the object's struct once and once only.

Does that help?

Marc
"Pohihihi" <no*****@hotmail.com> wrote in message
news:ul*************@tk2msftngp13.phx.gbl...
Well I got it now that Size is actually a struct which make sence for it
to throw that error. But still I disagree with the way Size.Width etc are
having comments. It gives a false idea what it is a property.
"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Documentation error maybe?

No, the documetation is correct. The property allows you to get and set
the size, that is, the Size structure as a whole.
If you are curious why you get such behavior, think about the fact that
Size is a value type object.


Dec 9 '05 #4
Sorry, but I don't think you do "get" it; the following works fine:
That might be right, I somethings feel like dumb myself.
Size size = new Size();
size.Height = 100;
size.Width = 100;
new Form().Size = size;

So the setters and getters are perfectly valid. The problem is that you
are expecting Size to behave like a class...
No, but because of the way commenting is done it seems like Width and Height
are properties of a class. I am talking about the comment/information you
see about something on intellisense.

Now size struct already have that comment thus any other object carrying
can't do much on that, that is what I meant by got it.

Essentially, by typing
textbox1.Size.Width = 100; ........
........ update the object's struct once and once only.
Does that help?


Yes, thanks.
Dec 10 '05 #5
The Size struct has no way of knowing (in any given scenario) whether it is
going to be held as a field/variable, ora accessed as a property, so there
is no way that it can "own" this aspects of the commenting. If you were
accessing the field directly (rather than using a property) this would not
be an issue. The Size's intellisense comments are 100% correct and 100%
appropriate.

However! If its that much of an issue for you, note that Control (a
base-class to TextBox) directly exposes the Width and Height properties,
which would do exactly what you want without the effort (but less
efficiently than setting both in one go via the Size).

Marc

"Pohihihi" <no*****@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Sorry, but I don't think you do "get" it; the following works fine:


That might be right, I somethings feel like dumb myself.
Size size = new Size();
size.Height = 100;
size.Width = 100;
new Form().Size = size;

So the setters and getters are perfectly valid. The problem is that you
are expecting Size to behave like a class...


No, but because of the way commenting is done it seems like Width and
Height are properties of a class. I am talking about the
comment/information you see about something on intellisense.

Now size struct already have that comment thus any other object carrying
can't do much on that, that is what I meant by got it.

Essentially, by typing
textbox1.Size.Width = 100;

.......
.......
update the object's struct once and once only.
Does that help?


Yes, thanks.

Dec 10 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
7
by: Daniel Kaplan | last post by:
I have the item below at the top of my style sheet. And it seems that the font-szie is ignored. I know that my linked style sheet is being read, and used because if I remove the font-family line,...
14
by: Galen Somerville | last post by:
My current screen resolution is set to 1024 x 768. My form size always comes up as 1032 x 748. I have tried the help sample ' Retrieve the working rectangle from the Screen class ' using the...
11
by: Parrot | last post by:
Is there any routine I can call to reduce the size of an image file after uploading a file from a client. I am looking to reduce file sizes programmatically using C# in my web page after uploading....
2
by: Dominique | last post by:
Hello, Im want to fix the width of a dashboard. I have a field which has a field (in this dashboard on the left part of my screen) which could be long and make the right side of the screen out...
7
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
0
by: benfly08 | last post by:
Hi, guys. I'm developing a web application for Sales Department people in my company. I used my 1024X768 resolution and "Medium" IE text size to test my Layout and it worked fine. However, some...
3
by: Mark Ivey | last post by:
VS.Net 2002 - Visual Basic I am pretty new to VB in general, and I am having a bit of difficulty finding the right method or property to link a textbox to a filelistbox. Here is the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.