|
I don't have any examples to give you, but as far as packing information for the selected control, just get the control that is passed as the sender for the MouseUp or MouseDown command. It will probably be easiest if you set a boolean flag in the MouseDown event, then in the MouseMove event do the drag-n-drop code if the boolean flag is set. In the MouseUp event, reset the boolean flag so that just passing over the control with the mouse doesn't begin a drag operation. Understand how drag and drop works will definitely help.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
That is exactly how I made my first drag and drop feature, before I learned about the drag / drop methods. Well, almost exactly.
I had a "CarryingItem" boolean, or something, this was a few months ago.
But that doesn't help with asigning a different type of IDataObject to the drag event. Can I just declare the object that I am dragging as IDataObject?
<br />
DragDropEffects dragArgs <br />
= DoDragDrop(dragData, DragDropEffects.All);<br />
where dragData is the customised IDataObject.
Or will this object just be packed into a conventional C# IDataObject, and still be rendered useless outside the C# enviroment?
I know how Drag and Drop works in the C# enviroment, but not in the native windows, is that what I need to understand?
Cata
|
|
|
|
|
Like I said in a previous post, you have to implement Win32's IDataObject and use that class. You'll have to P/Invoke DoDragDrop also, since .NET's method refers to the .NET IDataObject interface.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Right, I've looked at the methods and structures in COM, and I believe I can produce some managed counterparts with a little more work. The list of what I need follows:
Unmanaged Side:
Structures / Objects / methods:
1) Construct Managed IdropSource
2) Construct Managed FORMATETC structure
3) Construct Managed STGMEDIUM structure
4) Construct Managed IDataObject COM Object (All methods? Or only those that I will require?
5) Construct Managed DoDragDrop COM Object
Then, I will need to implement this in my C# enviroment, however, I'm not sure about handling these methods I have created, they strike me as one side managed, as in, the side that is transmitting is managed, but the recieving side (which in theory could be my own form) would not be, and this could cause some issues.
So I am looking at two possibilities as far as I understand. Now, while the first one looks easier, i am not sure it can actualy be done, when the mouse leaves form1, it could just enter a sub container / panel or whatever. So I am guessing I will have to implement the second one.
C# Side:
Options:
1) Construct C# DragDrop for internal drag and drop operations, and add Event upon mouse leaving the Form1 enviroment to switch the IdataObject to the managed COM version.
2) Use managed COM version of DragDrop method to begin with, and handle the COM functionality when dropped into other containers within the Form1 enviroment.
3) Any others?
Are there any other structures I will need to construct or handle? Will i need to handle the DragEnter and DragLeave events in COM and implement them in my form to use the second method, or can i leave them unhandled and let the OS take care of things? And are there any other options I am overlooking on the implementation side?
Thanks again Heath
Cata
(Maybe when i get this working I'll post some code and make it easy for everyone )
|
|
|
|
|
Why COM? I don't know extactly what he's doing here, but usually .NET's built-in DataObject[^](which implements IDataObject) works just fine. For example, to drag the file "c:\test.txt", you can do:
DataObject data=new DataObject();
data.SetData(DataFormats.FileDrop,new string[]{@"c:\test.txt"});
controlobject.DoDragDrop(data,DragDropEffects.All);
|
|
|
|
|
Spoke too soon. I looked farther down and found out that he needs to do a data stream.
|
|
|
|
|
Well If I could drop an object that the OS recognises and can convert to a file, that would work too...
It just makes more sense to use a stream as that seems to be the way apps communicate, and it requires minimal casting. A file drop should work fine. Please tell me more.
Cata
|
|
|
|
|
I tried to play with it, but I get the error:
"Cannot move file: Cannot read from then source file or disk"
So i take it, that my C# app is not compatible with windows.... or... something... *tired*
Will try tomorrow, but I think i'm going down with a severe case of man flu (runny nose = imobalisation for weeks, fatigue, and a life saving labotamy)
Cheers
Cata
|
|
|
|
|
The_Catalyst wrote:
I tried to play with it, but I get the error:
"Cannot move file: Cannot read from then source file or disk"
Umm... maybe you don't have a "c:\test.txt"?* Or did you forget to make it be @"c:\test.txt" or "c:\\test.txt"?
*I always have a "c:\test.txt" because that's such a convenient test filename.
|
|
|
|
|
I guess it's as Heath says, this won't work for me.
Oh well... time to go the hard way
Cata
|
|
|
|
|
Well, there's a number of different things you can do, provided that you have control of the application it's dropped to. Whether you have that control or not, I would have to have more details about what the circumstances are - what's being dragged and dropped, and to where, etc.
|
|
|
|
|
He wants to use an IStream that is a COM object so that the shell understands it. The IDataObject interface in .NET is much different than the IDataObject that is defined in objidl.h. The internals of how the .NET version is "marshaled" to the COM version is hidden in the System.Windows.Forms assembly (if memory serves me correctly), and it does basically what I've been telling Cata to do.
To my knowledge and from experience, the above code only sends filenames so the shell copies or moves those filenames (based on the allowed action). This person wants to know what the drop target is and apparently wants to do something when the target starts accessing the file(s). The only good way I could think of - since there aren't any notification interfaces I could find (in all my research and development with COM over the last many years) - was to use a stream because Cata would then know when the target was attempting to access the files.
If there is a better way to get notification that the object has been dropped (like, before the targets starts accessing the data object), I'm all ears. I've been looking for a solution for a couple years to this specific problem - even googling for discussions or samples - and have never found a good solution.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Sorry, didn't see your reply to yourself (I just use the emails I get to jump right to the topic and yours was off the screen.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, I've got a lot of things I want to do.
But yeah, i'd like to be able to drag an object from my listview, which will then produce the drag drop object from the data associated with the listview object that is dragged.
That is the simple part, as I can do it. But to get outside... there is where the real challenge is
I might even have to change the way I store the information in my program, which is a simple structure with Name, Type (File Extention), Data (the object). That's the thing i've packed up.
I'll look to basicaly write the object data to disk via the stream, and callit: <name>.<extention>
Then, when reversed, I can simply disect the file name back to my format, and drop the object data into my ObjectData object.
At least, that's the plan.
Cata
|
|
|
|
|
Hi,
How can I create from the outlook bar written in C++ by Dheth a control witch I can directly use in C#?
See: http://www.codeproject.com/miscctrl/outbar2.asp?target=outlook
Thanks in advance.
Gaby
|
|
|
|
|
Gaby,
I would suggest that you take a look at Marc Clifton's article: An Outlook Bar Implementation[^] written in C#, it is truely a great article from the ground up.
-Nick Parker
VB gets under people's skin because one can be ignorant of computer architecture and ASM and still
get a lot done. -Don Box
|
|
|
|
|
Hi,
Is there a simple way to print the current form to the default printer? I am working on a project for school and want to use a button on my form which does a "print screen"
|
|
|
|
|
Please search the comments for this forum. I just gave some advice to one person a few days ago about this. Basically, it's not very easy at all on C# but I gave some function reference that you should know and understand. The tips are there, but you have to figure out the solution. Besides, obviously, this is a homework question and we don't answer those in this - or any other - forum on CP. We'll give you tips and help if you're having a specific problem though.
It's just not right, and you won't learn anything by being given the answer.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I think there needs to be a message added to this board advising people to search the message board before posting and also trying msdn or google.
|
|
|
|
|
Suggestions should be posted here[^].
AK wrote:
I think there needs to be a message added to this board advising people to search the message board before posting and also trying msdn or google.
There is a saying: "You can lead a horse to water, but you can't make him drink."
You're assuming people will take the time to read it. For example, people still post programming questions in the Lounge even though there is a statement above the threads that indicates 'no programming questions'.
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
I dont know how basic this is but I am trying to create a file using a C# program.
Basicly I want a program that when you run it creates a text file that has on it a list of users.. Just like Console.WriteLine("Hello!") I want to put "Hello!" in a text file. Is this possible, if so -- please help Thanks alot
|
|
|
|
|
There are a myriad of different ways to write to a text file, take a look at the System.IO Namespace[^], in particular the TextWriter class if you are just starting out.
-Nick Parker
VB gets under people's skin because one can be ignorant of computer architecture and ASM and still
get a lot done. -Don Box
|
|
|
|
|
There are quite a few ways of creating files. Here's an easy one:
Using System.IO;<br />
<br />
string path = @"C:\MyTextFile.txt";<br />
StreamWriter writer = new StreamWriter(path, true);<br />
writer.WriteLine("Howdy!");<br />
writer.Close();
This appends text to the file if it already exists or creates a new one if it doesn't. There are many other options if you need more fine-grained control over the file's behavior. Check out the System.IO namespace for more info on them.
Charlie
Here I am. Love me.
|
|
|
|
|
try this as the first line in Main:
Console.SetOut( File.CreateText("console.log") );
Now everything goes to that file
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Thanks alot everyone!
|
|
|
|