.NET Framework - DockStyle value

Asked By Bulat Baltin on 12-Jun-07 09:11 AM
Hello,

I try to use Dock property in UserControl (if it matters) in the
following way

this.Dock = DockStyle.Left | DockStyle.Bottom | DockStyle.Right;

At runtime I gets :

System.ComponentModel.InvalidEnumArgumentException: The value of
argument 'value' (7) is invalid for Enum type 'DockStyle'.

How to fix it?

Regards,
Bulat Baltin




Alex Meleta replied on 13-Jun-07 01:38 AM
Hi,

because method this.Dock contains something like this:

if (!((value >= 0) && (value <= 5)))
{
throw new InvalidEnumArgumentException("value", (int) value,
typeof(DockStyle));
}

but DockStyle { None =0, Top, Bottom, Left = 3, Right = 4, Fill = 5 } with
combination DockStyle.Left | DockStyle.Right give you 7.

Regards,
Alex
http://devkids.blogspot.com
Bulat Baltin replied on 12-Jun-07 11:21 AM
Hello Alex,
Thanks. I just discovered that in my case

this.Dock = DockStyle.Bottom;

is enough and actually does what I wanted - docking to left and right
borders as well. The misleading fact for me was that in other place
for docking to left border I used

this.Dock = DockStyle.Top | DockStyle.Bottom | DockStyle.Left;

and it worked well. Now I see that DockStyle.Left is enough.

Regards,
Bulat Baltin.
G Himangi replied on 19-Jun-07 06:51 AM
You can only dock to one edge at a time...this means that the Dockstyle
values should not be or'ed

---------
- G Himangi,   Sky Software       http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------