Using the anchor property in visual c#


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Using the anchor property in visual c#

  1. #1
    Join Date
    Jan 2004
    Location
    Minneapolis, Minnesota
    Posts
    53

    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

  2. #2
    Join Date
    Jun 2004
    Posts
    93
    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"

  3. #3
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    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

  4. #4
    Join Date
    Jan 2004
    Location
    Minneapolis, Minnesota
    Posts
    53

    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

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by jnesbett View Post
    Thank you Jacques for your input.
    I would also like to add my thanks Jacques.
    Quote 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

  1. Yag's status report - March 28, 2002
    By Yair Alan Griver [MS] in forum vb.announcements
    Replies: 0
    Last Post: 03-28-2002, 07:28 PM
  2. YAG's public status report - March 7, 2002
    By Seth Grossman [MSFT] in forum vb.announcements
    Replies: 1
    Last Post: 03-13-2002, 07:32 PM
  3. YAG's status report - Feb 14, 2002
    By Seth Grossman [MSFT] in forum .NET
    Replies: 1
    Last Post: 02-15-2002, 12:35 AM
  4. Visual Studio.NET Resources
    By Robert Scoble in forum ASP.NET
    Replies: 0
    Last Post: 07-20-2000, 04:11 AM
  5. Visual Studio.NET Resources
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center