| | |
location and size questions
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
Solved Threads: 0
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:
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!
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:
C# Syntax (Toggle Plain Text)
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!
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.
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
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
Solved Threads: 0
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.
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.
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.
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.
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
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.
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.
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
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
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.
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
C# Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Trade Ad Space? (Ad Space for Sale)
- Skinny, normal or fat? (Geeks' Lounge)
- How can I submit a form as an email? (JSP)
- Inventory part 5 (Java)
- Urgent solution needed (C++)
- How do I overload [] operator for pointers (C++)
- Internal Frames (Java)
- Creating a Coordiantion (Grid Based) System for a text-based game. (C)
- MERGED: Deleting duplicates in an array (plz help me out!!!!!!!) (C)
- ** Need Help ** in a small C++ problem (C++)
Other Threads in the C# Forum
- Previous Thread: Total of 3 Newb Questions on This Code...
- Next Thread: drag and drop , copy and paste images
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox concurrency control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ globalization httpwebrequest image index input install java label list listbox listener mandelbrot math microsoftc#visualexpress mouseclick mysql networking operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






