3

https://msdn.microsoft.com/en-us/library/system.windows.forms.groupbox%28v=vs.110%29.aspx is a member of control

Container control is

https://msdn.microsoft.com/en-us/library/system.windows.forms.containercontrol%28v=vs.110%29.aspx

Provides focus-management functionality for controls that can function as a container for other controls.

Yet every member of system.form.control can contain another control.

If every member of control can contain another control why do we still have class system.windows.forms.containercontrol?

Also why groupbox which can contain another control are not member of container control class?

user4951
  • 32,206
  • 53
  • 172
  • 282

1 Answers1

3

This goes back to ancient times, 1985 and Windows version 1. GroupBox is actually, wait for it, a button. It has the BS_GROUPBOX style flag turned on. One more case where the Hungarian prefix is unintentionally descriptive :)

They had to do some pretty crazy things to cram a GUI operating system into available hardware, Windows 1 only required 192 KB of RAM. Letting the BUTTON class doing double-duty was one of them. Otherwise okay, every window is by design capable of acting like a parent control that hosts child controls, an ability that is often overlooked. You can find a practical example in this post. Whether a control acts like a container is expressed by ControlStyles.ContainerControl in Winforms.

The hangup is that ContainerControl derives from ScrollableControl, as you'd expect. Can't scroll a button.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536