c# label not dragging:
When I try and drag label into the rich text box, the icon stays as
rejected. My labels are in a panel, separate from the rich text box. How
can I get the text from the label to copy into the rich text box? Right
now I get the circle with a line as though I hadn't set txtText.AllowDrop
to true, but I did right there at the form load.
Below is most of my code. Thanks
private void frmMain_Load(object sender, EventArgs e)
{
txtText.AllowDrop = true;
txtText.DragDrop += new DragEventHandler(txtText_DragDrop);
txtText.DragEnter += new DragEventHandler(txtText_DragEnter);
txtText.MouseWheel += new MouseEventHandler(textBox1_MouseWheel);
}
void lblWord_MouseDown(object sender, MouseEventArgs e)
{
Label label = sender as Label;
DoDragDrop(label.Text, DragDropEffects.Copy);
}
void txtText_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
}
void txtText_DragDrop(object sender, DragEventArgs e)
{
string add = txtText.Text + " " +
(string)e.Data.GetData(DataFormats.Text);
txtText.Text = add.TrimStart();
}
No comments:
Post a Comment