-
Using the anchor property in visual c#
I am a newbe learning visual c#. I am experimenting with
the Anchor property in the properties window I have created
a test form and added a button to the form. I click on the
Anchor property in the properties window, which is currently
set to Top, Left. When I click on the drop down it shows
the top left rectangle highlighted. When I click on any of
the three other rectangles nothing happens. I am wondering
how to change the Anchor property for this button from
Top, Left to Top, Right. Is there another way of changing
the Anchor properties at development time beside clicking
one of ths rectangles? Is there some option that I have
checked that doesn't allow me to change the Anchor property?
Jerry Nesbett
Jerry Nesbett
-
the only think I can think of is that you cannot change the property if the project is currently running. It usually gives an error message like "invalid setting"
-
First of all, what do you expect the Anchor property to do?
This is a strange question, but as an instructor, I have found out that my students often misinterpret the use of that property.
Setting the property to Top, Right means that instead of staying fixed on the screen, the button will keep a constant distance for the top right corner of the form when it is resized. If you do not resize the form in any way, that property is useless.
That also automatically implies that if the FormBorderStyle of the form is set to anything but Sizable, the Anchor property does nothing.
Another factor to consider is that if the button is located inside a container (another control such as a Panel), the Anchor property is relative to the container and not to the form. Thus if the container has the default Top, Left anchor or does not resize when you resize the form, changing the Anchor property of any of its childs has no effect.
I have seen a few situations where in C# (not in VB however even if I use VB more often), the property does not seem to be active in the development environement. It works however in the compiled application.
Another situation I have encountered, but it was in an older version of Visual Studio, I do not remembre having that problem since 2005, was a Locked control that did not follow its Anchor. This somewhat makes sense since a Locked control is not supposed to move, but normally Anchor takes precedence.
Finally, since the Anchor can in some circumstances enable a change of size of the control, it interact with the AutoSize property. I do not see how it could affect a Top, Right setting which does not cause the control to change size, but you might want to revise the help for the AutoSize property in case one of the situations discussed is pertinent to your case.
Gook Luck.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
Changing the Anchor Property in Visual C# 2008
I am teaching myself Visual C# using James Foxall's book Teach Yourself Visual C# 2008 in 24 hours. In hour 6 he talks about the Anchor property.
I was trying to do what was in the book. Today I tried something different
and relaized that you don't click on the large rectangles, but you click on
the small rectangles that make up the larger rectangles, maybe they are
squares, to show which way you want the control anchored.
Thank you Jacques for your input.
Jerry Nesbett
Jerry Nesbett
-
 Originally Posted by jnesbett
Thank you Jacques for your input.
I would also like to add my thanks Jacques.
 Originally Posted by JBourgeois
I have seen a few situations where in C# (not in VB however even if I use VB more often), the property does not seem to be active in the development environement. It works however in the compiled application.
I could never get it to do anything in design (and now I know why) so I just stopped using it. This is handy to know.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Similar Threads
-
By Yair Alan Griver [MS] in forum vb.announcements
Replies: 0
Last Post: 03-28-2002, 07:28 PM
-
By Seth Grossman [MSFT] in forum vb.announcements
Replies: 1
Last Post: 03-13-2002, 07:32 PM
-
By Seth Grossman [MSFT] in forum .NET
Replies: 1
Last Post: 02-15-2002, 12:35 AM
-
By Robert Scoble in forum ASP.NET
Replies: 0
Last Post: 07-20-2000, 04:11 AM
-
By Robert Scoble in forum .NET
Replies: 0
Last Post: 07-20-2000, 04:11 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks