J
JezB
For a bitwise type like AnchorStyles the .NET runtime provides an easy way
to convert this to a string (like "Top, Left"), but is there an easy way to
convert it back again ? I've written my own method (see below) to do it but
it strikes me that there may be a much simpler way !
protected static AnchorStyles DeserializeAnchor(string a)
{
AnchorStyles retval = AnchorStyles.None;
if (a != "None")
{
if (a.IndexOf("Top") > -1) retval = retval | AnchorStyles.Top;
if (a.IndexOf("Bottom") > -1) retval = retval | AnchorStyles.Bottom;
if (a.IndexOf("Left") > -1) retval = retval | AnchorStyles.Left;
if (a.IndexOf("Right") > -1) retval = retval | AnchorStyles.Right;
}
return retval;
}
to convert this to a string (like "Top, Left"), but is there an easy way to
convert it back again ? I've written my own method (see below) to do it but
it strikes me that there may be a much simpler way !
protected static AnchorStyles DeserializeAnchor(string a)
{
AnchorStyles retval = AnchorStyles.None;
if (a != "None")
{
if (a.IndexOf("Top") > -1) retval = retval | AnchorStyles.Top;
if (a.IndexOf("Bottom") > -1) retval = retval | AnchorStyles.Bottom;
if (a.IndexOf("Left") > -1) retval = retval | AnchorStyles.Left;
if (a.IndexOf("Right") > -1) retval = retval | AnchorStyles.Right;
}
return retval;
}