1

I'm getting problems when trying to set the location of a couple of groupboxes...

This is a picture of the application in default size,

the groupboxes are in the middle of the form, and that's what I want. enter image description here

This is another picture, when the application is resized,

the groupboxes are moved to the left side, they are not still in the middle

The anchor property of the groupboxes are "Right" (I've tried all combinations) enter image description here

And this is a picture of the application when is full maximized,

the groupboxes are mover to the right side. enter image description here

I want to preserve the groupboxes in the middle of the tabpage when resizing.

Here's a video: http://www.youtube.com/watch?v=itZ85hRh9dQ&feature=youtu.be

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    Yeah, WinForms isn't really great for this kind of thing. You will likely need to reposition and resize them from code when the Form.OnResize event is fired. WPF is the way forward, and this kind of thing is supported – musefan Jul 02 '13 at 12:45
  • maybe you can use panel .. make them in the panel and take care the panel position on form resize event .. – matzone Jul 02 '13 at 12:51
  • 1
    @musefan thanks for the "possible duplicate", in the link i saw the solution is to don't try any anchor combination, set anchor to "None" , solved! – ElektroStudios Jul 02 '13 at 13:33

1 Answers1

2

Perhaps if you don't find any other solution you could replace them on the form_resize event. I think you used Groupboxes... This helps a lot! You should do something like this for the single GroupBoxes (as Program in your example):

groupBox1.Location.X = Me.Width / 2 - groupBox1.Width / 2

And something like this for more GroupBoxes horizontally (as Files and Customization)

Dim dist As Int32 = groupBoxCustomization.Location.X - groupBoxFiles.Width + groupBoxFiles.Location.X
'Get the distance between groupBoxCustomization and groupBoxFiles
Dim groupWidth As Int32 = groupBoxCustomization.Width + groupBoxCustomization.Location.X - groupBoxFiles.Location.X
'Get the total width of the GroupBoxes including the distance between them
'Now you use the same system than before, just imagine to have only one large GroupBox
groupBoxFiles.Location.X = Me.Width / 2 - groupWidth / 2
'Now you have fixed the first GroupBox, you know the distance between the GroupBoxes, and the widths are constant, so it's easy!
groupBoxCustomization.Location.X = groupBoxFiles.Location.X + groupBoxFiles.Width + dist

You may need to convert calculations to Integer, if so, use this code

intValue = CInt(double)

Hope this helps (and works... I haven't tried it) :)

Cippo
  • 1,001
  • 4
  • 14
  • 26