예제 #1
0
        /// <summary>
        /// Paste text from clipboard into selected position
        /// </summary>
        public static void Paste(FastColoredTextBox textbox)
        {
            string text = null;
            var thread = new Thread(() =>
            {
                if (Clipboard.ContainsText())
                    text = Clipboard.GetText();
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            // get result from event handler, because pasting could be cancelled.
            TextChangingEventArgs result = textbox.OnPasting(text);

            if (result.Cancel)
            {
                text = string.Empty;
            }
            else
            {
                text = result.InsertingText;
            }

            if (!string.IsNullOrEmpty(text))
            {
                textbox.InsertText(text);
            }
        }