DevExpressContrib.Core.DxExtensions

Coordinator
Nov 25, 2008 at 4:09 AM
Some normal tasks in DevExpress controls can be non-trivial. It struck me today that some of these tasks could be made trivial via Extension Methods.
One of these non-trivial tasks is to append a line to a MemoEdit. This evening I threw together this class. It will be included in the next source dump of DevExpressContrib.

dlx

#region Copyright © 2008, DevLynx (MIT License)

// This software is licensed under The MIT License:

//

// Permission is hereby granted, free of charge, to any person obtaining a copy

// of this software and associated documentation files (the "Software"), to deal

// in the Software without restriction, including without limitation the rights

// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

// copies of the Software, and to permit persons to whom the Software is

// furnished to do so, subject to the following conditions:

//

// The above copyright notice and this permission notice shall be included in

// all copies or substantial portions of the Software.

//

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

// THE SOFTWARE.

#endregion

 

namespace DevExpressContrib.Core.DxExtensions

{

    using System;

    using System.Collections;

    using System.Windows.Forms;

    using DevExpress.XtraEditors;

 

    public static class DxExtensions

    {

        public static void Append(this MemoEdit memo, string line)

        {

            TextBox textBox = GetMemoEditInnerTextBox(memo);

            if (textBox != null)

                textBox.AppendText(line);

        }

 

        public static void AppendLine(this MemoEdit memo, string line)

        {

            if (memo.Lines.Length > 0)

                line = "\n" + line;

            memo.Append(line);

        }

 

        public static void AppendLine(this MemoEdit memo)

        {

            memo.AppendLine(String.Empty);

        }

 

        public static void AppendLineNoScroll(this MemoEdit memo, string line)

        {

            ArrayList array = new ArrayList(memo.Lines);

            array.Add(line);

            memo.Lines = array.ToArray(typeof(string)) as string[];

        }

 

        public static void AppendLineNoScroll(this MemoEdit memo)

        {

            memo.AppendLineNoScroll(String.Empty);

        }

 

       private static TextBox GetMemoEditInnerTextBox(TextEdit editor)

        {

            if (editor != null)

                foreach (Control control in editor.Controls)

                    if (control is TextBox)

                        return (TextBox)control;

            return null;

        }

    }

}