Thanks for the post. It was already set to the top left and still does not work. Any other clue?
Jason
I am trying to change just my control width on a resize. If the form is maximized, I want my control to widen so much. If the form is made smaller, I want it to shrink a bit.
How can this be done?
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
Me.Button1.Location = New System.Drawing.Point(176, 144)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(240, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.TextBox2.Location = New System.Drawing.Point(8, 32)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(240, 104)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(256, 174)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox2, Me.TextBox1, Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Thanks for the sample. That is what I did. Here is my code block: Me.listConfig = New System.Windows.Forms.ListBox()
Me.listConfig.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
Me.listConfig.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.listConfig.HorizontalScrollbar = True
Me.listConfig.Location = New System.Drawing.Point(8, 8)
Me.listConfig.Name = "listConfig"
Me.listConfig.Size = New System.Drawing.Size(576, 236)
Me.listConfig.TabIndex = 0Do you know why my code is keeping the control to the bottom instead of spanning it across?
Thanks for all your help so far! ;)
If you want the control to expand left-to-right, then you must anchor the control to the left and to the right. If you want it to expand downwards, then you must anchor it to both the top and bottom. Just try the various options, really. There are only a few combinations, and it should be immediately apparent when you've hit the right one.