location and size questions
Hi all!
Well, again I find myself stuck in a silly situation. I've found some more settings that seem to baffle me.
First off all, why can't I set the Right property of a control?
Example:
PictureBox ExamplePictureBox = new PictureBox();
ExamplePictureBox.Right = 50;
This returns that "Property or indexer 'System.Windows.Forms.Control.Right' cannot be assigned to -- it is read only (CS0200)"
So... why can I perfectly assign a Left property but not a Right? Same goes for Bottom.
Secondary question, is there a way to allign/dock/anchor something in the way that I want some button to stick to the upper-right corner no matter what (maybe insert some margin of 10 pixels, but I can probably figure that out)? I have tried to Anchor it using something like (AnchorStyle.Top | AnchorStyle.Right) (not sure of the term AnchorStyle, but something along those lines) but that didn't work.
Then a Location question. The intellisense tells me I can either get or set stuff to it, though every time I try to use something like this.Location.X = 250; It tells me it isn't a variable and won't build... The same goes for DesktopLocation and several others I have found and tried but can't remember at the moment. Which property should I set to manually assign a location? (The point of this is that I would like to have a status-form on the right side of my main form, maybe that clarifies some stuff)
Thanks for the help and time!
ctrl-alt-del
Junior Poster in Training
66 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
I don't know either why that is.
You should ask the implementors of the TextBox class.
What I do know is that you cannot set the Height of a TextBox with a MultiLine property set to false. (the default) In this case the height depends on the height of the Font used.
I also know a Rectangle is a Point and a Size (among others).
This seems to be the only option for a TextBox.
So if you want to change the Location of a TextBox, change it by assigning a new Point to it. TextBox.Location.X = 50; will not work either.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Hi all!
Okay, then the new Point is clear enough to me, define a new point, assign it and use the variable Point to assign a new location.
The controls in question are PictureBox and Form by the way, TextBox is more or less known to me since they don't have a whole lot of options.
Well, I guess the question is still sort of open, that's a first from my experience :P If anybody else has some ideas please post them, and I will see what MSDN has to offer! (And if I happen to find a solution before it is posted here, I will of course let you guys know!)
Thanks for the help so far.
ctrl-alt-del
Junior Poster in Training
66 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
Hi all!
Thanks you very much for the information!! I will try and work with the Anchor and AnchorStyle's and see if I can fit in a margin (I'm not using any VisualStyles so I don't have a border and placing something right on the edge looks horrible. any tips or hints on that would also be appreciated)
And I'll see if I find it usefull enough to write a simple function to place something on the right side of something else.
Thank you for all your help, this clarifies it all, at least enough for me to move on.
Will leave this thread open for 12-24 hours for any more responses. then I will marked it solved.
ctrl-alt-del
Junior Poster in Training
66 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
Hi all!
Thank you very much for all the help, this has gotten me all the help I needed.
For reference to others:
The Location property needs a variable like this
Point ExamplePoint = new Point(200, 200);
this.Location = ExamplePoint;
And the Right property is read-only and just used for reference. (Which makes me wonder why people don't just use Width.)
And last but not least, the DesktopLocation can also be used on your MainForm but has to be AFTER your form has been created, NOT before. I prefer to load things like that in the this.Load event, but I guess there are other and maybe better ways.
Last 12 hours go into effect now.
Muchos gracias everyone! Once again you've provided all the info I need.
ctrl-alt-del
Junior Poster in Training
66 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0