Link to home
Create AccountLog in
Avatar of Russell_Venable
Russell_VenableFlag for United States of America

asked on

Drag and Drop in textbox W7

Why wont the cursor change to allow drag & drop operations? Is this feature disabled some how or there a new approach in windows 7? I am suprised something this simple is not working. Please show me the correct format if you have a working solution.  All this should do is return the filename of file being droped into the textbox, but instead it just shows the slashed circle.

This is what I have.

textBox1.AllowDrop is set to true in properties

using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;

namespace givemd5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static StringBuilder build = new StringBuilder();
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                open.CheckFileExists = true;
                open.CheckPathExists = true;
                open.ShowDialog();

                MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
                FileStream File = new FileStream(open.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                label1.Text = "File Selected: " + (open.FileName);
                MD5.ComputeHash(File);
                byte[] hash = MD5.Hash;

                foreach (byte num in hash)
                {
                    build.Append(String.Format("{0:X2}", num).Trim());
                    textBox2.Text = build.ToString();
                }
                File.Close();
            }
            catch (NullReferenceException ex)
            {
                MessageBox.Show("NullReferenceException: " + ex.Message);
            }
        }

        private void linkLabel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (textBox2.Text.Length > 0)
                Clipboard.SetText(textBox2.Text);
            else
                MessageBox.Show("No hash to Copy!");
        }

        private void textBox1_DragDrop(object sender, DragEventArgs e)
        {
            string File = (string)e.Data.GetData(DataFormats.FileDrop, false);
            textBox1.Text = File;
        }

        private void textBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
        }

        private void textBox1_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }

        }
    }
}

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

It seems to work fine for me  : \
Avatar of Russell_Venable

ASKER

Hmm it keeps Giving me the " the can't drop here" symbol maybe it's just a w7 pro thing
Sorry, I tried to post a screencast, but it didn't upload. I am using Win Pro as well.
This is a screencast of what I am doing and the results. Isn't this weird? I really don't know how to fix this.
Russell-Venable-384695.flv
ASKER CERTIFIED SOLUTION
Avatar of Russell_Venable
Russell_Venable
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
No other solution points to a answer. So I am now posting the solution as it was odd enough.