Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Drag And Drop

Drag And Drop

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewbProgrammer
    wrote on last edited by
    #1

    Well im going to try to ask this question in the most understandable way... This is what im trying to do: I have a Rich Text Box on a form. When you drag a file onto the rich text box (Presumably a text file) it opens it and copies all of the text onto the rich text box. Im thinking that it will somehow have to find out the location of the file, open it and use stream reader to read it. If anyone has ANY suggestions please write a message. Thank You :) MWA HAHAHAHA I AM A NOOB AND WE NOOBS WILL KILL YOU ALL. JK Whats intresting is that im only 12 years old :P

    D 1 Reply Last reply
    0
    • N NewbProgrammer

      Well im going to try to ask this question in the most understandable way... This is what im trying to do: I have a Rich Text Box on a form. When you drag a file onto the rich text box (Presumably a text file) it opens it and copies all of the text onto the rich text box. Im thinking that it will somehow have to find out the location of the file, open it and use stream reader to read it. If anyone has ANY suggestions please write a message. Thank You :) MWA HAHAHAHA I AM A NOOB AND WE NOOBS WILL KILL YOU ALL. JK Whats intresting is that im only 12 years old :P

      D Offline
      D Offline
      DigitalKing
      wrote on last edited by
      #2

      You are correct. Do something like this:

      public Form1()
      {
      InitializeComponent();
      richTextBox1.DragEnter += new DragEventHandler(richTextBox1_DragEnter);
      richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
      }

      void richTextBox1_DragDrop(object sender, DragEventArgs e)
      {
      string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); //array of the full paths of all files that were dropped
      if (files.Length > 0)
      {
      try
      {
      System.IO.StreamReader r = new System.IO.StreamReader(files[0]);
      richTextBox1.Text = r.ReadToEnd();
      }
      catch (Exception ex)
      {
      System.Diagnostics.Debug.WriteLine("Error opening file " + files[0] + ":\n"+ex.Message);
      }
      }
      }

      void richTextBox1_DragEnter(object sender, DragEventArgs e)
      {
      if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
      {
      e.Effect = DragDropEffects.All;
      }
      }

      Hope this helps, DigitalKing

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups