Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How would I open a .txt that is dropped (from the mouse carrying over the file) onto the form? Then I want Textbox.Text to equal the text from the .txt.

 

How could I do this? :confused:

"Reality is fake, Dreams are for real"
  • Leaders
Posted
do you wish to Drag-Drop , or is the .txt file already in exsistance on the system? because you could always use the StreamReader to put the text in to your textbox if the file exsists somewhere.

Posted

Well the Text File is going to be on the system. But when the person drag-and-drops the Text File on the Program Form, I want the Text File to open on the Program Form and also know the path of the Text File that was drag-and-dropped from the system.

 

If that doesn't make sense then this should lol :p :

 

 

Carry over TextFile from Desktop --> Program Form --> Open TextFile, and put text in TextBox1 --> Store the path of the TextFile into a string.

"Reality is fake, Dreams are for real"
Posted

It is not as hard as you might think. Don't think in terms of dragging the actual file on your form, just an image or something that REPRESENTS your text file. Then, when the user drops it on the TB you open and read the file which they chose into the text boxs' Text property.

 

The hardest part is handling the drag drop mechanism. Before you do that I suggest getting familiar with reading and writing text files using StreamReader and StreamWriter, then you will have a better understanding of how to do what you are trying to do here. It is quite simple.

C#
Posted
Don't think in terms of dragging the actual file on your form, just an image or something that REPRESENTS your text file.

 

Image?! Now I'm totally lost, you see I want the user to drag-and-drop a text file, I don't see how I could use an image file to be dropped and display text inside of the TextBox.Text.

 

 

 

The hardest part is handling the drag drop mechanism. Before you do that I suggest getting familiar with reading and writing text files using StreamReader and StreamWriter, then you will have a better understanding of how to do what you are trying to do here. It is quite simple.

 

 

I'm pretty familiar with StreamReader and StreamWriter but I don't know how to connect them to something that's being dragged and dropped, or how to enable drag-and-drop from a .txt onto a TextBox.

"Reality is fake, Dreams are for real"
Posted

you see what i actually is

 

im not sure of the correct event for the text box

 

but it waits for any events and stuff

 

what happens the file passes an argument

 

your first job would be to save the path to anything u want

 

id say stick it into a temp variable

 

 

then call ur load text file subroutine pointing to the temp variable

 

from that point u can save the temp variable to the registy or what so ever

Posted
I don't see how I could use an image file to be dropped and display text inside of the TextBox.Text

That is just it, you do not actually drag the text, just something that REPRESENTS it.

C#
Posted

I did not explain that very well. You will only handle mouse events. The image or different mouse pointer that represents any drug file is not for you at all but for the user, a Graphical User Interface (GUI). So to you, the programmer, the picture is nothing.

 

Is the example posted above sufficient? It may be hard to actually see what I am talking about from the code posted above because the .net controls hide alot of things.

C#
Posted
You will only handle mouse events. The image or different mouse pointer that represents any drug file is not for you at all but for the user, a Graphical User Interface (GUI). So to you, the programmer, the picture is nothing.

 

Is the example posted above sufficient? It may be hard to actually see what I am talking about from the code posted above because the .net controls hide alot of things.

 

Ummm..Well drag-and-drop is from the mouse, but when you said:

 

"...any drug file is not for you at all but for the user"

 

So the user = the form (GUI)?

 

But what does the picture = ?

 

I think I'm an image learner lol :(

"Reality is fake, Dreams are for real"
Posted

im not sure what aewarnick is quite refering to

 

are you refering to as in the drag and drop GUI representation

 

or just a simple structural representation of how drag and drop inter-relates using diagrams and flow charts?

Posted

If you want to show the content of a text file upon drag and drop this will do it:

 

private void DragDrop(object sender, System.Windows.Forms.DragEventArgs e)

{

 

string[] s = (string[])e.Data.GetData(DataFormats.FileDrop,false);

if(s.Length == 1)

{

System.IO.StreamReader sr =

new System.IO.StreamReader(s[0]) ;

string FileContents = "" ;

FileContents = sr.ReadToEnd() ;

sr.Close() ;

textBox1.Text = FileContents ;

}

}

Posted

All I am saying is that you the programmer are not checking for a drag drop picture at all, you just handle the mouse events, which are made simple in .net with DragDrop events. The special Drag Icon is for the user not the programmer and it does not hold the actual file at all.

 

I know when I thought about drag drop as a beginning programmer I thought that the user was dragging the file itself.

 

An example will show this better and I figured that the example above (the attatched code) was an example that would show what I was talking about. I did not look at it though.

 

So the user = the form (GUI)?

The user is not the form the user is the person using your program through the GUI.

And you don't have to mess with the pictrue in .net unless you want to. When a user holds down the mouse and moves accross a listbox the drag drop icon becomes the cursor.

 

Sorry to confuse you. I just wanted you to see how the internals work without showing code. Good luck!

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...