Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- namespace R718ArrastrarYSoltar
- {
- public partial class Principal : Form
- {
- public Principal()
- {
- InitializeComponent();
- rtbTexto.AllowDrop = true;
- rtbTexto.EnableAutoDragDrop = false;
- rtbTexto.DragDrop += rtbTexto_DragDrop;
- rtbTexto.DragEnter += rtbTexto_DragEnter;
- }
- private void rtbTexto_DragDrop(object sender, DragEventArgs e)
- {
- RichTextBox rtbRichTextBox = sender as RichTextBox;
- if (rtbRichTextBox != null)
- {
- int pos = rtbRichTextBox.SelectionStart;
- string textoNuevo = rtbRichTextBox.Text.Substring(0, pos)
- + e.Data.GetData(DataFormats.Text).ToString()
- + rtbRichTextBox.Text.Substring(pos);
- rtbRichTextBox.Text = textoNuevo;
- }
- }
- private void rtbTexto_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.Text))
- {
- e.Effect = DragDropEffects.Copy;
- }
- else
- {
- e.Effect = DragDropEffects.None;
- }
- }
- private void rtbTexto_MouseDown(object sender, MouseEventArgs e)
- {
- RichTextBox rtbRichTextBox = sender as RichTextBox;
- if (sender != null && rtbRichTextBox.SelectionLength > 0 && Form.MouseButtons == MouseButtons.Left)
- {
- int pos = rtbRichTextBox.GetCharIndexFromPosition(e.Location);
- if (pos > rtbRichTextBox.SelectionStart &&
- pos <= (rtbRichTextBox.SelectionStart + rtbRichTextBox.SelectionLength))
- {
- rtbRichTextBox.DoDragDrop(rtbRichTextBox.SelectedText, DragDropEffects.Copy);
- }
- }
- }
- private void txtFuente_DragDrop(object sender, DragEventArgs e)
- {
- TextBox txtTextBox = sender as TextBox;
- if (txtTextBox != null)
- {
- txtTextBox.Text = (String) e.Data.GetData(DataFormats.Text);
- }
- }
- private void txtFuente_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.Text))
- {
- e.Effect = DragDropEffects.Copy;
- }
- else
- {
- e.Effect = DragDropEffects.None;
- }
- }
- private void txtFuente_MouseDown(object sender, MouseEventArgs e)
- {
- TextBox txtTextBox = sender as TextBox;
- if (txtTextBox != null && Form.MouseButtons == MouseButtons.Left)
- {
- txtTextBox.SelectAll();
- txtTextBox.DoDragDrop(txtTextBox.Text, DragDropEffects.Copy);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement