AddControl() public method

Adds a control to the TextInputWindow. The control will automatically be positioned below the previously-added control. The spacing can be controlled through the control's Margin property.
If you are adding a control after a label, you may need to adjust the label's height. By default it's bigger than usually desired.
public AddControl ( Control control, AboveOrBelow aboveOrBelow = AboveOrBelow.Below ) : void
control System.Windows.Forms.Control The control to add
aboveOrBelow AboveOrBelow
return void
        internal static void AddEntityToolStripClick()
        {
            // search:  addentity, add entity
            if (ProjectManager.GlueProjectSave == null)
            {
                System.Windows.Forms.MessageBox.Show("You need to load a project first.");
            }
            else
            {
                if (ProjectManager.StatusCheck() == ProjectManager.CheckResult.Passed)
                {
                    TextInputWindow tiw = new TextInputWindow();
                    tiw.DisplayText = "Enter a name for the new Entity";
                    tiw.Text = "New Entity";

                    CheckBox is2DCheckBox = new CheckBox();
                    is2DCheckBox.Text = "Is 2D";
                    is2DCheckBox.Checked = true;
                    is2DCheckBox.Margin = new Padding(2, 0, 0, 0);

                    tiw.AddControl(is2DCheckBox);

                    if (tiw.ShowDialog(MainGlueWindow.Self) == DialogResult.OK)
                    {

                        string entityName = tiw.Result;

                        string whyIsntValid;
                        string directory = "";

                        if (EditorLogic.CurrentTreeNode.IsDirectoryNode())
                        {
                            directory = EditorLogic.CurrentTreeNode.GetRelativePath();
                            directory = directory.Replace('/', '\\');
                        }

                        if (!NameVerifier.IsEntityNameValid(tiw.Result, null, out whyIsntValid))
                        {
                            MessageBox.Show(whyIsntValid);
                        }
                        else
                        {
                            var newElement = 
                                GlueCommands.Self.GluxCommands.EntityCommands.AddEntity(directory + tiw.Result, is2DCheckBox.Checked);

                            GlueState.Self.CurrentElement = newElement;

                        }
                    }
                }
            }
        }
        private static AddObjectViewModel CreateAndShowAddNamedObjectWindow()
        {
            AddObjectViewModel addObjectViewModel = new AddObjectViewModel();

            TextInputWindow tiw = new TextInputWindow();
            tiw.DisplayText = "Enter the new object's name";
            tiw.Text = "New Object";
            bool isTypePredetermined =  EditorLogic.CurrentNamedObject != null && EditorLogic.CurrentNamedObject.IsList;

            NewObjectTypeSelectionControl typeSelectControl = null;
            if (!isTypePredetermined)
            {
                tiw.Width = 400;


                typeSelectControl = new NewObjectTypeSelectionControl();
                typeSelectControl.Width = tiw.Width - 22;

                typeSelectControl.AfterStrongSelect += delegate
                {
                    tiw.ClickOk();
                };

                typeSelectControl.AfterSelect += delegate(object sender, EventArgs args)
                {
                    string result = tiw.Result;

                    bool isDefault = string.IsNullOrEmpty(result);

                    // Victor Chelaru November 3, 2012
                    // I don't know if we want to only re-assign when default.
                    // The downside is that the user may have already entered a
                    // name, an then changed the type.  This would result in the
                    // user-entered name being overwritten.  However, if we don't
                    // change the name, then an old name that the user entered which
                    // is specific to the type may not get reset.  I'm leaning towards
                    // always changing the name to help prevent misnaming, and it's also
                    // less programatically complex.
                    //if (isDefault)
                    {
                        string newName;

                        if(!string.IsNullOrEmpty(typeSelectControl.SourceFile) && !string.IsNullOrEmpty(typeSelectControl.SourceName))
                        {
                            newName = HandleObjectInFileSelected(typeSelectControl);
                        }
                        else if (string.IsNullOrEmpty(typeSelectControl.SourceClassType))
                        {
                            newName = "ObjectInstance";

                        }
                        else
                        {

                            string textToAssign = typeSelectControl.SourceClassType + "Instance";
                            if (textToAssign.Contains("/") || textToAssign.Contains("\\"))
                            {
                                textToAssign = FileManager.RemovePath(textToAssign);
                            }

                            newName = textToAssign.Replace("<T>", "");
                        }

                        // We need to make sure this is a unique name.
                        newName = StringFunctions.MakeStringUnique(newName, EditorLogic.CurrentElement.AllNamedObjects);
                        tiw.Result = newName;
                    }
                };
                tiw.AddControl(typeSelectControl, AboveOrBelow.Above);
            }

            addObjectViewModel.DialogResult = tiw.ShowDialog();

            addObjectViewModel.SourceType = SourceType.FlatRedBallType;
            addObjectViewModel.SourceClassType = null;
            addObjectViewModel.SourceFile = null;
            addObjectViewModel.SourceNameInFile = null;
            addObjectViewModel.SourceClassGenericType = null;
            addObjectViewModel.ObjectName = tiw.Result;

            if(isTypePredetermined)
            {
                var parentList = GlueState.Self.CurrentNamedObjectSave;

                var genericType = parentList.SourceClassGenericType;

                if(!string.IsNullOrEmpty(genericType))
                {
                    addObjectViewModel.SourceClassType = genericType;
                    
                    // the generic type will be fully qualified (like FlatRedBall.Sprite)
                    // but object types for FRB primitives are not qualified, so we need to remove
                    // any dots

                    if(addObjectViewModel.SourceClassType.Contains("."))
                    {
                        int lastDot = addObjectViewModel.SourceClassType.LastIndexOf('.');

                        addObjectViewModel.SourceClassType = addObjectViewModel.SourceClassType.Substring(lastDot + 1);
                    }

                    if(ObjectFinder.Self.GetEntitySave(genericType) != null)
                    {
                        addObjectViewModel.SourceType = SourceType.Entity;
                    }
                    else
                    {
                        addObjectViewModel.SourceType = SourceType.FlatRedBallType;
                    }
                }
            }

            if (typeSelectControl != null)
            {
                if (!string.IsNullOrEmpty(typeSelectControl.SourceClassType) || typeSelectControl.SourceType == SourceType.File)
                {
                    addObjectViewModel.SourceType = typeSelectControl.SourceType;
                }
                addObjectViewModel.SourceFile = typeSelectControl.SourceFile;
                addObjectViewModel.SourceNameInFile = typeSelectControl.SourceName;

                addObjectViewModel.SourceClassType = typeSelectControl.SourceClassType;
                addObjectViewModel.SourceClassGenericType = typeSelectControl.SourceClassGenericType;
            }

            return addObjectViewModel;
        }