0

I want copy the big text data from any source(such as :other app,word,notepad,...) and paste to my textBox in my app.now I must be detect enterLine from copied text.

I search so much but cant any solution.

tanx a lot

4

1 回答 1

1

您可以通过专门为您的要求创建自定义文本框,在 WinForms TextBox 控件的默认“粘贴”事件上创建挂钩,如下所示。

using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class MyTextBox : TextBox 
    {
        protected override void WndProc(ref Message m)
        {
            // Trap WM_PASTE:
            if (m.Msg == 0x302 && Clipboard.ContainsText())
            {
                var pastText = Clipboard.GetText().Replace('\n', ' ');
                if (pastText.Length > MaxLength)
                {
                    //Do Something 
                }
                else
                {
                    //Do Something 
                }
                this.SelectedText = pastText;
                return;
            }
            base.WndProc(ref m);
        }
    }
}
于 2013-06-09T09:35:35.747 回答