Keeping controls centered

  • Thread starter Thread starter Chris Saunders
  • Start date Start date
C

Chris Saunders

This is not actually a C# question but I'm not sure which newsgroup is
appropriate for
this question. My apologies if I'm being "off-topic".

I'm writing and application that has a group box that contains a bunch of
radio buttons
and wish to keep this group box and its buttons centered when the width of
the window
is changed. I do know how to accomplish this using code but I wonder if
there is a
simpler method? I'm using Visual Studio 2005 to write this application.

Regards
Chris Saunders
 
This is not actually a C# question but I'm not sure which newsgroup is
appropriate for
this question. My apologies if I'm being "off-topic".

I'm writing and application that has a group box that contains a bunch of
radio buttons
and wish to keep this group box and its buttons centered when the width of
the window
is changed. I do know how to accomplish this using code but I wonder if
there is a
simpler method? I'm using Visual Studio 2005 to write this application.

You may be stuck doing this in code. The best chance you have for
doing it using layout containers would be the standard
TableLayoutPanel, but even that doesn't let you center things easily.
You could make a 3 x 3 table and put your control in the center. You
could then set the second row's RowStyle to Absolute, and the second
column's ColumnStyle to Absolute, and set the others to 50 Percent.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.rowstyles.aspx

If you're lucky, this will cause the center cell to stay the size you
want it, while allocating half the remaining space to the top and
bottom rows, and the right and left columns of the table layout. I
make no promises though: I haven't tried it myself. :-)

Also, check out the following;

http://msdn2.microsoft.com/en-us/library/ms171691.aspx
 
Chris said:
This is not actually a C# question but I'm not sure which newsgroup
is appropriate for this question. My apologies if I'm being
"off-topic".

I'm writing and application that has a group box that contains a
bunch of radio buttons and wish to keep this group box and its
buttons centered when the width of the window is changed. I do know
how to accomplish this using code but I wonder if there is a simpler
method? I'm using Visual Studio 2005 to write this application.

Simply anchor it only to the bottom of the form while pre-centering it
in the designer. Then when you resize the window, the groupbox will
stay centered.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Simply anchor it only to the bottom of the form while pre-centering it
in the designer. Then when you resize the window, the groupbox will
stay centered.

Really! I had no idea!

Does that work in 1.1 as well as 2.0? Or is it a WPF thing?
 
Bruce Wood said:
Really! I had no idea!

Does that work in 1.1 as well as 2.0? Or is it a WPF thing?

It's a .Net 2.0 Framework thing. It's easier in WPF (but it's about the
only thing that is). ;-)

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
RobinS said:
newsgroup >>> is appropriate for this question. My apologies if I'm
being >>> "off-topic".
know >>> how to accomplish this using code but I wonder if there is a
simpler >>> method? I'm using Visual Studio 2005 to write this
application.

It's a .Net 2.0 Framework thing. It's easier in WPF (but it's about
the only thing that is). ;-)


Nonsense, it works since .NET 1.0.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Bruce said:
Really! I had no idea!

Does that work in 1.1 as well as 2.0? Or is it a WPF thing?

It works since .NET 1.0 :)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Frans Bouma said:
RobinS said:
Bruce Wood said:
On Feb 4, 2:07 am, "Frans Bouma [C# MVP]"
Chris Saunders wrote:
This is not actually a C# question but I'm not sure which
newsgroup >>> is appropriate for this question. My apologies if I'm
being >>> "off-topic".
I'm writing and application that has a group box that contains a
bunch of radio buttons and wish to keep this group box and its
buttons centered when the width of the window is changed. I do
know >>> how to accomplish this using code but I wonder if there is a
simpler >>> method? I'm using Visual Studio 2005 to write this
application.
Simply anchor it only to the bottom of the form while pre-centering it
in the designer. Then when you resize the window, the groupbox
will stay centered.

Really! I had no idea!

Does that work in 1.1 as well as 2.0? Or is it a WPF thing?

It's a .Net 2.0 Framework thing. It's easier in WPF (but it's about
the only thing that is). ;-)


Nonsense, it works since .NET 1.0.

FB

I stand corrected! Thanks!
Robin S.
 
My thanks to all who responded to this question. I've been ill so I didn't
see the responses until today.
The group box I wanted to stay centered was at the top of the window so I
anchored it to the top alone
and this worked fine. Thanks again.

Regards
Chris Saunders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top