简体   繁体   中英

Why is this code not dynamically setting the groupbox control anchor property?

Here is the code:

Private WithEvents modderInfoGroup As New NSGroupBox
modderInfoGroup.Text = ""
modderInfoGroup.Location = New Point(3, 3)
modderInfoGroup.Size = New Size(512, 424)
modderInfoGroup.DrawSeperator = True
modderInfoGroup.Title = currentModder
modderInfoGroup.SubTitle = "Modder Information"
modderInfoGroup.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Bottom Or AnchorStyles.Right
myTabPage.Controls.Add(modderInfoGroup)
myTabPage.Name = "modder" & modderNumber

When creating the Control dynamically is defaults to Top and Left but i want it to set it to all 4 edges. Anyone got a fix?

This is a Windows Form(WinForm) in Visual Studio 2015.

If you are trying to fill the space of the container control, then the property you want to set is the Dock property:

modderInfoGroup.Dock = DockStyle.Fill

The anchor property was working, but the initial size didn't match the size of the client area of the parent control. To make that work, you would have to set the size to that client size:

modderInfoGroup.Location = Point.Empty
modderInfoGroup.Size = MyTabPage.ClientSize

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM