Diablicolic Posted August 5, 2003 Posted August 5, 2003 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: Quote "Reality is fake, Dreams are for real"
Leaders dynamic_sysop Posted August 5, 2003 Leaders Posted August 5, 2003 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. Quote
jorge Posted August 5, 2003 Posted August 5, 2003 I thing what he main if you drag let say file.txt from you desktop onto his form, it wil open file.txt and read the cotnent and isplay it into the textbox Quote Jorge - http://www.blackdot.be/?page=apache.htm
Diablicolic Posted August 5, 2003 Author Posted August 5, 2003 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. Quote "Reality is fake, Dreams are for real"
aewarnick Posted August 6, 2003 Posted August 6, 2003 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. Quote C#
Diablicolic Posted August 6, 2003 Author Posted August 6, 2003 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. Quote "Reality is fake, Dreams are for real"
Winston Posted August 6, 2003 Posted August 6, 2003 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 Quote
Winston Posted August 6, 2003 Posted August 6, 2003 here i whipped ya up an example of wat u want it to dodrag and drop file into text.zip Quote
aewarnick Posted August 6, 2003 Posted August 6, 2003 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. Quote C#
Diablicolic Posted August 6, 2003 Author Posted August 6, 2003 aewarnick, you're going to have to give an example, :p Thank you Winston, I'm truly spoiled :rolleyes: Quote "Reality is fake, Dreams are for real"
aewarnick Posted August 7, 2003 Posted August 7, 2003 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. Quote C#
Diablicolic Posted August 7, 2003 Author Posted August 7, 2003 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 :( Quote "Reality is fake, Dreams are for real"
Winston Posted August 7, 2003 Posted August 7, 2003 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? Quote
BryanZM Posted August 7, 2003 Posted August 7, 2003 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 ; } } Quote
aewarnick Posted August 7, 2003 Posted August 7, 2003 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! Quote C#
Winston Posted August 7, 2003 Posted August 7, 2003 if im not mistaken are you refering to the drag effectts? with the little bounded doted square when u drag a file into a draggable area Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.