Autoscroll is not working on dynamic form
I have a form with a button on it that will dynamically create a new form.
I add all the labels, textboxes and buttons on the fly based on a text
file. I thought I would be able to use the "frmDynamic.AutoScroll = True"
command to add scroll bars if there are too many controls on the form but
it is not working. Here is the related settings to the form
frmDynamic = New Form()
frmDynamic.AutoScaleDimensions = New
System.Drawing.SizeF(6.0F, 13.0F)
frmDynamic.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font
frmDynamic.Name = "frmDynamicMerchantApplication"
'dimension is irrelevant at the moment
frmDynamic.ClientSize = New System.Drawing.Size(10, 10)
'the parent will be the current form
'frm.MdiParent = this;
frmDynamic.ControlBox = True
frmDynamic.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.Sizable
' This needs to be GrowOnly for the auto scroll to work. -
otherwise you have to add scrollbars manually along with the
handlers and so forth.
frmDynamic.AutoSizeMode =
System.Windows.Forms.AutoSizeMode.GrowOnly
' Add auto scroll since the form could grow out of range when
adding multiple references and owners
frmDynamic.AutoScroll = True
In addition I attempted to set the "pad.AutoScrollMinSize = new
System.Drawing.Size(300, 0)" property also but nothing seems to work - I
get no scroll bar.
As a final test I have set the AutoScroll property to true on the main
form and it works fine when the form is sized smaller than the objects
positions. As a final test I added another button on the main form with
the following code to create a form with autoscroll set to true and it
works fine.
' Create a new form.
Dim form2 As New Form()
' Create a button to add to the new form.
Dim button1 As New Button()
' Set text for the button.
button1.Text = "Scrolled Button"
' Set the size of the button.
button1.Size = New Size(100, 30)
' Set the location of the button to be outside the form's client
area.
button1.Location = New Point(form2.Size.Width + 200,
form2.Size.Height + 200)
' Add the button control to the new form.
form2.Controls.Add(button1)
' Set the AutoScroll property to true to provide scrollbars.
form2.AutoScroll = True
' Display the new form as a dialog box.
form2.ShowDialog()
Is there any form settings that could be stopping this functionality?
No comments:
Post a Comment