Basically i am doing a drag and drop using textbox and labels , by dragging a label to a textbox . Textboxes and Labels are created in same for loop .
I have dynamically created textboxes ( textbox is the drop target) like this :
TextBox tbox = new TextBox();
tbox.Width = 250;
tbox.Height = 50;
tbox.AllowDrop = true;
tbox.FontSize = 24;
tbox.BorderThickness = new Thickness(2);
tbox.BorderBrush = Brushes.BlanchedAlmond;
tbox.Drop += new DragEventHandler(tbox_Drop);
if (lstQuestion[i].Answer.Trim().Length > 0)
{
wrapPanel2.Children.Add(tbox);
answers.Add(lbl.Content.ToString());
MatchWords.Add(question.Content.ToString(), lbl.Content.ToString());
}
I have also dynanmically create labels ( label is the drag target) like this :
Dictionary<string, string> shuffled = Shuffle(MatchWords);
foreach (KeyValuePair<string, string> s in shuffled)
{
Label lbl = new Label();
lbl.Content = s.Value;
lbl.Width = 100;
lbl.Height = 50;
lbl.FontSize = 24;
lbl.DragEnter += new DragEventHandler(lbl_DragEnter);
lbl.MouseMove += new MouseEventHandler(lbl_MouseMove);
lbl.MouseDown +=new MouseButtonEventHandler(lbl_MouseDown);
// lbl.MouseUp +=new MouseButtonEventHandler(lbl_MouseUp);
dockPanel1.Children.Add(lbl);
}
I have 2 issues here .
1st . I am using tbox.drop event to display MessageBox.Show( something ) ; to display a messagebox when the drag target is being drop but it doesn't work .
here is my code :
private void tbox_Drop(object sender, DragEventArgs e)
{
MessageBox.Show("Are you sure?");
}
Second , i also want to clear the tbox.Text when the drag target is dropped because i might have other drag target dropped into the tbox previously. So i want to clear the tbox.Text and drop the drag target everytime when i drag the target to textbox .
How do i do that? i am stucked at which event i should use for this and how do i access tbox from those event handlers ?