Reputation: 2642
I have 20 graphs on a form; they are wide rectangles. So now I need to put a raw number next to the graphs. I will change this number while the graphing routine draws a line depicting it.
I need to do this 20 times; one for each channel. The user chooses where the rectangles will be (via some NumericUpDown controls).
As a result, the 20 rectangles holding the 20 graphs will be in 20 different locations; generally consistent, but still variable. I handle this with five ints; i.e., X_start, Y_start, Height, Width, Spacing
.
My first thought was to make 20 labels, place them next to the graphs, and change the the text in them.
I read about making an array of labels here
Then I tried to code it like this...
for (int i = 0; i < 20; i++)
{
RawNumberLabels[i].Text = "0";
RawNumberLabels[i].Location.X = RawNumberLabel_x; // error
}
The error says.. Cannot modify (blah blah blah "Location.X") because it is not a variable.
So I tried this:
Point RawXY = new Point((int)RawNumberLabel_x, Y_Pos);
for (int i = 0; i < 20; i++)
{
RawNumberLabels[i].Text = "0";
RawNumberLabels[i].Location.Offset(RawXY); // fixes that one
// Then this next line is all full of fail
RawNumberLabels[i].Size.Width = (int)UpDownsFromTheUser.Starting_RawNumberWidth;
Now I can't change Size.Width
because it's not a variable.
Okay, so how do I put 20 labels next to 20 other rectangles on the screen, so that their X, Y, Height, and width fit neatly with the X, Y, and height of those 20 other rectangles?
Better yet, is there a better way to put 20 raw numbers next to 20 rectangles like this?
Upvotes: 0
Views: 912
Reputation: 13706
From the documentation:
Because the
Size
class is a value type (Structure
in Visual Basic,struct
in Visual C#), it is returned by value, meaning accessing the property returns a copy of the size of the control. So, adjusting the Width or Height properties of the Size returned from this property will not affect the Width or Height of the control. To adjust the Width or Height of the control, you must set the control's Width or Height property, or set the Size property with a new Size.
Edit: Here is the Label class, which might be a good reference point for this.
Upvotes: 1