none
How do you get a drag and drop event for a WPF textbox hosted in a Windows Form

    Pertanyaan

  • So I have a WPF text box in my Windows Forms. In the WPF text box I have checked the option AllowDrop. In Windows Form, when I look at the properties of this text box there is no event for drag and drop like there is for a Windows Forms text box, so what is the code for getting drag and drop set up. Just to clarify, I mean drag and drop a file.

    Stackoverflow seem unwilling or unable to give a reply to this question, questioning why I don't use the textbox in WinForms. The answer to that if you need to know is that textbox in WinForms is limited to 1024 characters per line. Above this 1024 limit and you get a line wrap which in turn effects line count. WPF textbox does not have this limit, but I don't know how to make events to it, hence....

    08 Mei 2018 7:33

Semua Balasan

  • Hi Jon,

    WPF textbox does not have an event named DragDrop, instead, it has another events: 

            private void button1_Click(object sender, EventArgs e)
            {
                System.Windows.Controls.TextBox txt = new System.Windows.Controls.TextBox();
                txt.PreviewDrop += Txt_PreviewDrop;
                txt.PreviewDragEnter += Txt_PreviewDragEnter;
            }
    
            private void Txt_PreviewDragEnter(object sender, System.Windows.DragEventArgs e)
            {
                //...
            }
    
            private void Txt_PreviewDrop(object sender, System.Windows.DragEventArgs e)
            {
                //...
            }

    Please refer to the following document about drag/drop in WPF:

    Textbox Drag/Drop in WPF

    Note: I'm afraid this question is more related to WPF controls, if you have more questions about WPF controls, it will be more appropriate to ask your question at WPF forum.

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    08 Mei 2018 8:08
  • I will ask it there. Thanks for trying, but I don't see what button1_Click has to do with a hosted control... but no matter.
    08 Mei 2018 8:50
  • but I don't see what button1_Click has to do with a hosted control... but no matter.

    Hi,

    I just told you how to define an event for WPF control in Winform in above code.

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    09 Mei 2018 1:51