|
Unless, I don't perform the dragdrop operation immediately, and when the file is completed, I could then pull the file path from the COM method, and move the file using that?
|
|
|
|
|
The_Catalyst wrote:
4) What about multiple files? Can the drag drop method handle multiple objects? Construct 5-6 objects by stream, and then enable the drag and drop?
Yes it can. The DataFormats.FileDrop clipboard format is a managed string[] array, which gets marshaled correctly so that Windows can understand it.
You know, in as many questions and answers that have been posted about your problem, you have never once mentioned what you are trying to do. Perhaps someone has a better solution overall than what you are trying to do. This may help things.
Also, yes, creating the files when the mouse leaves the form (which is possible) would be incredibly inefficient and would probably just piss-off your users since the CPU would spike and their shell would appear to hang for a while. The stream way I've mentioned before is about the only way to know when something is requesting the file(s) that you are providing.
-----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 have a list view, and a tree view. They are synchronised (The active folder in the tree view displays it's contents (an ArrayList assigned the the TAG object) in the list view).
I can drag stuff between folders in the tree view, and rearange the list view all well and good.
It's similar to winzip with winMPQ elements, only I intend to add methods to the archive to automaticaly present a content map to a program that wishes to access it.
While I have written a program to import and export files and objects via a fileDialogBox, i would like to implement drag and drop of list view objects (or the data they represent) into the list / folder view both two and from the windows enviroment.
I have the dragging from windows enviroment working, extracting the data and adding it to the TAG, then refreshing the listview, and performing an Icon lookup based on the extention.
The objects I would like to drag out of the enviroment will have their data extracted and assigned to ObjectData.Data, and the filepath will be constructed from *name*.*extention*.
<br />
struct ObjectData<br />
{<br />
object data;<br />
string name;<br />
string extention;<br />
}
Looking at it now, it may well be worth my while using the predefined ObjectData object instead of my own version. That should not be too difficult to accomplish, but which version should I use? COM, or .NET?
I can implement the COM object that I need, but I am unsure of how to manage the transition between COM DataObjects and the .NET version. When, where and how, if at all, should they be replaced? Only for drops outside the enviroment? Or inside as well? Will I have to handle the managed COM objects for internal drops if I want to use it at all?
Cata
|
|
|
|
|
You'd probably need to use the COM IDataObject , but you don't translate this to or form the .NET version. It's all P/Invoked calls (like the native DoDragDrop function), structures (like STDMEDIUM and FORMATETC ), and interfaces (like IDataObject , IDragSource , and IStrea ). The .NET drag-n-drop isn't used in this solution. It is an overly simplified implementation that won't do what you need. I've actually read the IL behind these classes and .NET uses this same approach - eventually the IDataObject is transformed into COM's and the native methods are used, but these are internal and you cannot access them except through reflection (and that would be even harder).
-----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-----
|
|
|
|
|
So i will just have to handle the COM versions? I can't use the .NET drag and drop at all, even for internal moves?
(Just making sure I understand you :p )
Cata
|
|
|
|
|
You could use it for internal moves and you can even use the events to trigger the COM routines, but it will be hard distinguishing whether or not you'll need to do .NET or COM routines. Either way, the end result is the same. Remember that the .NET routines, interfaces, etc., are built on top of the Win32 drag-n-drop, so you can still use the .NET events for dropping in your application, but you should use the COM routines to pack the data how you want.
-----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-----
|
|
|
|
|
So overwrite the DoDragDrop method, replace the structures with managed COM structures etc, and just let .NET interact with it in the way it was designed.
The only problem I can see is, will .NET recognise the new method and handle the mouse pointer shape automaticaly? Or is that windows that manges that and determines whether it is a dropable location?
I'm going to assume it's windows and get on with it at some point when I feel better.
God I hate Colds. They ruin thought processes
Cat
|
|
|
|
|
No, don't override DoDragDrop . For one, it's not virtual (meaning you have to declare it with the new ) keyword. Second, the data parameter expects an IDataObject (or temporary, unformatted Object ) from .NET - not COM (type Types, while named the same, are still different Types).
You need to P/Invoke the native DoDragDrop functions. I only meant that you could initiate drag-n-drop using the same event handlers but using the P/Invoked code. Your drop targets can use the managed drag-n-drop events because the data object will by seen by .NET the same way. If you want to support the same formats as the DataFormats class fields, just use the same format IDs as they have (which you can find by using the same strings (check the fields' values) or the IDs, which you can get from the Win32 headers).
-----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-----
|
|
|
|
|
Gotcha.
I shall crack on with it.
I'll let you know how I go, and when I got it working, I suppose the lease I could do is stick the code up on CP.
Thanks again for helping me get my head around that one.
I just had the biggest "AAAAAHHHHH!!!" moment when the penny dropped.
Cata
|
|
|
|
|
I have a Rich Text Box Control. In which i want that only text along with its formatting(bold, color etc) be pasted. But it should discard IF clipboard item contains Image.
I tried using
if(!(Clipboard.GetDataObject().GetDataPresent(DataFormats.Bitmap)))
{
Clipboard.GetDataObject().GetFormats();
this.Paste();
}
but does not allow Image to be pasted but if data to be pasted contains Image and Text both it fails to restrict.
I also tried with DataFormats.Text but then only text is pasted and formatting is lost. Can anybody help me.
|
|
|
|
|
There are different types of image data formats you should check, not just DataFormats.Bitmap . That only specifies a Windows Bitmap and while some programs may put both, for example, JPG and its uncompressed BMP format in the data object, some might not. So make sure you check that there are no images. This would be an exclusive approach.
You could also use an inclusive approach. If you only want formatted or plain text inserted, that check for the existence of those and only those by using DataObject.GetFormats and making sure that all the string array elements are what you want (which reminds me, your call Clipboard.GetDataObject.GetFormats() is useless since you aren't using it's return value - is just a waste of instructions). This would be an inclusive approach and can better limit what you accept in your RichTextBox . Just check for DataFormats.Rtf , DataFormats.Text , DataFormats.UnicodeText , and/or DataFormats.OemText .
The latter method is probably better because the clipboard formats (which are also used in drag-n-drop routines) are not limited to what's in the DataFormats class. Those are just some common ones that are pre-registered by Windows and understandable in .NET. Applications can easily make up their own formats and there are other common formats that the RichTextBox might understand.
-----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-----
|
|
|
|
|
Hi,
I have an FTP server by some users. Each user has a folder and can add or delete a file in his specified folder.
Now I want that I'm notifed by email when a user makes any change in his folder.
Can I use C# to do this situation?
Does FTP server provide me this situation or I have to develop a program?
regards,
Mehdi
|
|
|
|
|
Doing this via FTP would be difficult - if even possible. About the only way is to poll the folders and check for recent changes. A better way would be to write a program that uses the FileSystemWatcher component to watch the directories on the server (i.e., not via FTP but on the file system itself) and alerts you of changes.
-----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-----
|
|
|
|
|
Hi.
I've got a button with no text (only and icon) and I need a shortcut key (accelerator key) to the button.
Normally i would do something like "Cl&ose" to use the "o" as a shortcut, but my button has no text, so how do i accimplish this?
|
|
|
|
|
Set KeyPreview to true on your Form that contains the button and handle the KeyDown or KeyUp event, which will give you the active modifier keys (Alt, Ctrl, and/or Shift) and the key that was pressed in a KeyEventArgs passed to the event handler.
-----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 extended my menuitem with an additional property. it works well with the property editor.
now I need write some code to detect and change the extended properties. I tried using the folowing code but it is not "detecting" the extended properties.
<br />
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(menuItem1);<br />
foreach (PropertyDescriptor myProperty in properties)<br />
textBox1.Text += myProperty.Description.ToString() + '\n';<br />
how can I detect and edit extended properties?
thank you...
Peter Kaiser
|
|
|
|
|
"detect and edit" is rather ambiguous and perhaps you could clarify.
If you are talking about getting and setting values, see the PropertyDescriptor.GetValue and PropertyDescriptor.SetValue , which both use the PropertyDescriptor for your Type, and you pass your actual object (menuItem1 ) so that you get the value for that property on that object. See the SDK documentation for those two methods for more information and examples.
-----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-----
|
|
|
|
|
Thank you, I will try to explain:
I used
[ProvideProperty("ImageIndex", typeof(MenuItem))]
to "add" the Property "ImageIndex" to MenuItem.
Now I want to move through all MenuItems by code and set the values of "ImageIndex".
(More abstract I would prefer to move through all components, check if they have the extended property "ImageIndex" and set the value)
Peter Kaiser
|
|
|
|
|
You should really read about providers. You're doing it completely wrong. You can just add a property like that - you can extend the MenuItem and add properties and methods, or you can create a type designer or editor that can simulate a property at design-time and that writes out code to make use of that "virtual" property. Essentially, this is what IExtenderProviders are, and you must implement that interface and provide the Type as the second parameter to the ProvidePropertyAttribute . Be sure to read about those two things in the .NET SDK documentation.
This amounts to another component that actually stores the values on behalf of the attributes class (or rather, and instance of that class). So, the MenuItem doesn't actually have that property, but another components would. If you name the property ImageIndex , then your extender provider would have a SetImageIndex and GetImageIndex method, as well as some optional specially-named methods to help with serialization.
There is a great couple articles about extender providers, including an example of what you're trying to do (adding an image easily to a menu) here at CP:It's always a good idea to try searching first before posting a question. Chances are that is has been asked / solved before and you'll get answers quicker than waiting for a reply.
Be sure to read the documentation for IExtenderProvider and ProvidePropertyAttribute as well.
-----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-----
|
|
|
|
|
thank you...
I know, that MenuItem doesn't actually have that property!
I know whta you wrote me about the extender provider and his set and get-methods!
I also know about the metioned articles, because I used Menu Images!
I just wanted to know, if there is a chance to find out if there is a extender provider for a component, and how to get and set the values of its properties at runtime..
Peter Kaiser
|
|
|
|
|
If you know what you are doing, then why did you have MenuItem as the Type of the provider?! This won't work.
If you need to figure out if your extender provider has a value for the control, then you need to add a property to your extender provider that contains a list of the controls for which it handles. Also, extender providers usually work in such a way that any instance of that type has a provided property, and if it doesn't you should make sure of it. James's article presents a good way to do this (the Ensure* methods) so that you never get null when you don't expect it.
-----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-----
|
|
|
|
|
hi all
i am working on small project , i need help.......
how can i implement start button (like in windows)for my application ?
thanks alote
|
|
|
|
|
What do you mean? A button which pops up a menu when you click it? Or a button which looks just like the start button?
If the first: Use the ContextMenu control.
If the latter: Under Windows XP you can use UXTheme.dll (and some C# wrapper) to skin your button.
[EDIT]Oops. Didn't read you message's subject line. But please clarify anyway.[/EDIT]
- Daniël Pelsmaeker
|
|
|
|
|
hey,
i know it's kind a silly to ask but does anyone know of a way to conver a C# program into an dos-executable? I do not need the win-32 graphics, just the core routines. Can anyone give he a clou how to do this (without rewriting the whole bunch)
Thanx a lot
Jeroen
|
|
|
|
|
When you create your project, select "Console Application"
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|