Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Manipulating Forms with the Windows Forms ...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Manipulating Forms with the Windows Forms Library
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-02-22

    Table of Contents:
  • Manipulating Forms with the Windows Forms Library
  • 4.11 Attaching a Control to the Edge of a Form
  • 4.12 Moving or Resizing Controls as a Form Resizes
  • 4.13 Limiting the Sizing of a Form

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Manipulating Forms with the Windows Forms Library - 4.12 Moving or Resizing Controls as a Form Resizes
    (Page 3 of 4 )

     Problem

    You want a control to move or stretch in proportion to how the form is resized.

    Solution

    Use the control’s Anchor property to attach it to one or more sides of the form.

    Discussion

    Setting the Anchor property of a control tells that control to permanently maintain a consistent distance relationship with one or more sides of the form or container. You can anchor a control to any or all of the four sides of a form. By default, controls are anchored to the left and top sides of the form. This means that as the form resizes, the controls remain the same distance from the form’s left and top edges (i.e., they do not appear to move).

    The availableAnchor property choices includeLeft,Top,Right, andBottom, and you can use them in any combination. The following list shows the types of combinations you can use with theAnchorproperty:

    Anchored to one side

    As the form is resized, the center point of the control along the anchored edge is matched to a position on that form edge relative to the changing size of the form. The size of the control does not change. For instance, if a control is anchored to the top of a form and the form is made wider, the control moves to the right in proportion to the size of the form, as shown in Figure 4-12.


    Figure 4-12.  The top-anchored control moves when the form is resized

    Anchored to two adjacent sides

    As the form is resized, the control maintains its distance from both anchor sides. In other words, it seems to be joined to the corner that is shared by the two anchor sides. By default, most controls anchor to the left and top sides of the form and do not appear to move when the right and bottom borders of the form are moved in a resize operation.

    Anchored to two opposite sides

    The anchor sides of the control remain a fixed distance from the anchor borders. For instance, if a control is anchored on the left and right, the control grows by the same number of pixels as the form is widened (see Figure 4-13). When the unanchored direction is resized, the control is moved to keep the portion of space between the unanchored sides and the control the same, but the control is not resized in that direction.


    Figure 4-13.  The left-and-right-anchored control stretches as the form widens

    Anchored to three sides

    The control resizes between the two anchor sides that are opposite to each other and remains the same distance from the single anchor border, as shown in Figure 4-14.


    Figure 4-14.  Anchored to top, left, and right, the edges of the control remain a fixed distance from all but the bottom edge of the form

    Anchored to all four sides

    The control is continually resized with the form. All its sides stay the same distance from all anchored form borders, as shown in Figure 4-15.

    Figure 4-15.  Anchored to top, left, bottom, and right, the proportions of the control change in concert with the form's proportions

    Anchoring also applies to panels and other containers that can include subordinate controls.

    See Also

    See Recipe 4.11 for details on the Dock property, which you can use to attach a control to one side of a form’s client area. The Dock andAnchor properties cannot be used at the same time on the same control. The last one you set on that control is the one used.

    More Visual Basic.NET Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Visual Basic 2005 Cookbook," published by...
     

    Buy this book now. This article is excerpted from chapter four of the Visual Basic 2005 Cookbook, written by Tim Patrick and John Clark Craig (O'Reilly; ISBN: 0596101775). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway