location and size questions

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

location and size questions

 
0
  #1
Sep 16th, 2009
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:
  1. PictureBox ExamplePictureBox = new PictureBox();
  2. 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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,984
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 289
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: location and size questions

 
0
  #2
Sep 16th, 2009
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

Re: location and size questions

 
0
  #3
Sep 16th, 2009
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 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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 333
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 39
Diamonddrake's Avatar
Diamonddrake Diamonddrake is offline Offline
Posting Whiz

Re: location and size questions

 
1
  #4
Sep 16th, 2009
ok lets jump off this dock.

the X and Y properties of a location type cannot be set directly. so no you can't set them that way.

the "anchor" property should do what you want, but only if the position of your controls is set prior to the setting of the anchor property. ( in code execution order)
that looks something like this.
[icode=csharp]
Control.Anchor = AnchorStyles.Top | AnchorStyles.Right
[/icode]

the control.Right property is "get" only. that means it tells you the distance in pixels from the right edge of the control to the right edge of the parent control, you can't set it because its actually just a calculation, it doesn't point toward an actual variable. it looks something like this...
[Code = csharp]
Public Int string Right()
{
get
{
return (this.Location.X + this.Width) - this.Parent.Width;
}
}
[/code]

So setting it will fail.


you can also manually stick a control to the top right corner using the forms on resize event, but the anchor property does just fine.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

Re: location and size questions

 
0
  #5
Sep 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 333
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 39
Diamonddrake's Avatar
Diamonddrake Diamonddrake is offline Offline
Posting Whiz

Re: location and size questions

 
0
  #6
Sep 16th, 2009
Glad i could help, and as for the padding, just place the control the distance from the anchored sides that you want it to stay, and then the anchor property handles it for you , it will stay the same distance from the anchored edges at all times.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

Re: location and size questions

 
0
  #7
Sep 17th, 2009
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
  1. Point ExamplePoint = new Point(200, 200);
  2. 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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC