![]() |
Controls Properties: |
|
Introduction |
|
When a control is added to a host, depending on the control, it may be automatically positioned where the mouse landed. In some cases, you will want the control to be attached to a border or to a corner of its parent. This can be done using the Dock property: ![]() |
|
This property is managed through the DockStyle enumeration. To use this property, click the control and, in the Properties window, click the arrow of the Dock field. You can then select one of the following values: Bottom: The control will be attached to the bottom border of its parent:
Fill: The control will use the whole client area of its parent. Left: The control will be attached to the left border of its parent:
None: The control will be kept where it was positioned on the parent:
Right: The control will be attached to the right border of its parent:
Top: The control will be attached to the top border of its parent:
To programmatically specify the docking option of a control, access its Dock property and assign the desired member of the DockStyle enumeration. Here is an example: Imports System
Imports System.Drawing
Imports System.Windows.Forms
Module Exercise
Public Class WinControls
Inherits Form
Private btnSubmit As Button
Dim components As System.ComponentModel.Container
Public Sub New()
InitializeComponent()
End Sub
Public Sub InitializeComponent()
btnSubmit = New Button()
btnSubmit.Text = "Submit"
btnSubmit.Location = New Point(20, 20)
btnSubmit.Size = New Size(100, 60)
btnSubmit.Dock = DockStyle.Right
Controls.Add(btnSubmit)
End Sub
Public Shared Function Main() As Integer
Application.Run(New WinControls())
Return 0
End Function
End Class
End Module
This would produce:
|
|
|
||
| Home | Copyright © 2008 FunctionX, Inc. | Home |
|
|
||