I'm a rather novice programmer who recently came up with a solution that works for my project, however I'm always looking for ways to improve my code. So essentially, I have a settings form that pop's up and I was looking for a way to put it next to my main form but not covering it nor appearing partially off of the screen the main form is on.  I came up with this but it's not very dynamic because it only checks 4 different locations and if none of them work it uses the default, which is center screen.Here is what I have:private void Place_Form(Form formToPlaceNextTo, Form formToPlace)    {        Point alignRightTop = new Point(m_parent.Location.X + m_parent.Width, m_parent.Location.Y);        Point alignRightBottom = new Point(m_parent.Location.X + m_parent.Width, (m_parent.Location.Y + m_parent.Height) - this.Height);        Point alignLeftTop = new Point(m_parent.Location.X - this.Width, m_parent.Location.Y);        Point alignLeftBottom = new Point(m_parent.Location.X - this.Width, (m_parent.Location.Y + m_parent.Height) - this.Height);        if (Screen.FromControl(formToPlace).WorkingArea.Contains(new Rectangle(alignRightTop.X, alignRightTop.Y, this.Width, this.Height)))        {            this.Location = alignRightTop;            return;        }        if (Screen.FromControl(formToPlace).WorkingArea.Contains(new Rectangle(alignRightBottom.X, alignRightBottom.Y, this.Width, this.Height)))        {            this.Location = alignRightBottom;            return;        }        if (Screen.FromControl(formToPlace).WorkingArea.Contains(new Rectangle(alignLeftTop.X, alignLeftTop.Y, this.Width, this.Height)))        {            this.Location = alignLeftTop;            return;        }        if (Screen.FromControl(formToPlace).WorkingArea.Contains(new Rectangle(alignLeftBottom.X, alignLeftBottom.Y, this.Width, this.Height)))        {            this.Location = alignLeftBottom;            return;        }    }Any suggestions or preferred coding techniques?Addendum#1:  I agree that it's easier and probably more preferred to let the framework decide where to put forms, however this settings form changes the visual look of the main form and the default position of the settings form is almost directly on top of the main form.  This poses a problem in regards to user friendliness (in my eyes).
Is there a more elegant way of arranging my forms?
c#;winforms
My bad, I think see now what you wanted. I just did not feel like reading your logic fully (too many details). After I did read it, I saw that you got the details right. All you needed was to stick your points into a list or enumerate over them, as in this example. This way, if you feel like adding more options - you can. Let me know if this works, so that I can delete the other answer.private void Place_Form(Form formToPlaceNextTo, Form formToPlace){    foreach (Point pointToTry in EnumerateFormPlacement(formToPlaceNextTo, formToPlace))    {        var rectToTry = new Rectangle(pointToTry.X, pointToTry.Y, formToPlace.Width, formtoPlace.Height);        if (Screen.FromControl(formToPlace).WorkingArea.Contains(rectToTry))        {            formToPlace.Location = pointToTry;            return;        }    }    // Else no match, hence default location.}private IEnumerable<Point> EnumerateFormPlacement(Form formToPlaceNextTo, Form formToPlace){    Point alignRightTop = new Point(        formToPlaceNextTo.Location.X + formToPlaceNextTo.Width,        formToPlaceNextTo.Location.Y);    yield return alignRightTop;    Point alignRightBottom = new Point(        formToPlaceNextTo.Location.X + formToPlaceNextTo.Width,         (formToPlaceNextTo.Location.Y + formToPlaceNextTo.Height) - formToPlace.Height);    yield return alignRightBottom;    Point alignLeftTop = new Point(        formToPlaceNextTo.Location.X - formToPlace.Width,        formToPlaceNextTo.Location.Y);    yield return alignLeftTop;    Point alignLeftBottom = new Point(        formToPlaceNextTo.Location.X - formToPlace.Width,        (formToPlaceNextTo.Location.Y + formToPlaceNextTo.Height) - formToPlace.Height);    yield return alignLeftBottom;}