相关疑难解决方法(0)

WPF C# 拖放

基本上,我通过将标签拖动到文本框来使用文本框和标签进行拖放。文本框和标签是在同一个 for 循环中创建的。

我已经动态创建了文本框(文本框是放置目标),如下所示:

  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()); 

            }
Run Code Online (Sandbox Code Playgroud)

我还动态地创建标签(标签是拖动目标),如下所示:

  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); …
Run Code Online (Sandbox Code Playgroud)

c# wpf label textbox drag-and-drop

5
推荐指数
1
解决办法
9568
查看次数

标签 统计

c# ×1

drag-and-drop ×1

label ×1

textbox ×1

wpf ×1