LitDev.LDFocus.SetFocus C# (CSharp) Method

SetFocus() public static method

Sets the named shape to have focus.
public static SetFocus ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name (usually a textbox). ///
return Primitive
        public static Primitive SetFocus(Primitive shapeName)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary<string, UIElement> _objectsMap;
            UIElement obj;

            try
            {
                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                    return "False";
                }

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate { return obj.Focus(); });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "False";
            }
        }