Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2005

Tip: Looking for answers? Try searching our database.

Drag & Drop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michi - 29 Sep 2005 09:03 GMT
Hi

Does anybody know how I can display own icons for drag & drop ?

thx
Oliver Sturm - 29 Sep 2005 10:33 GMT
>Does anybody know how I can display own icons for drag & drop ?

You need to use a few Windows API functions ImageList_DragXXX to do this.
There's a sample that shows how to do this here:

  http://www.codeproject.com/cs/miscctrl/TreeViewDragDrop.asp

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Michi - 29 Sep 2005 10:59 GMT
wow. much code for this little thing...

thanks for the link/sample project

>>Does anybody know how I can display own icons for drag & drop ?
>
[quoted text clipped - 4 lines]
>
>                Oliver Sturm
Dan Neely - 29 Sep 2005 13:26 GMT
> wow. much code for this little thing...
>
> thanks for the link/sample project

The raw win32api is much more verbose than the .net wrappers written around
it.  Whenever you need something not provided by the wrappers you have to do
it the old way, which as you saw requires much more userwritten code.  The
.net classes do all of that too, it's just behind the scenes for you.
Danny Tuppeny - 29 Sep 2005 13:21 GMT
>>Does anybody know how I can display own icons for drag & drop ?
>
> You need to use a few Windows API functions ImageList_DragXXX to do this.
> There's a sample that shows how to do this here:
>
>   http://www.codeproject.com/cs/miscctrl/TreeViewDragDrop.asp

Does this mean it can't be done with no/low-trust apps like those run via
ClickOnce? :(
Oliver Sturm - 29 Sep 2005 13:34 GMT
>Does this mean it can't be done with no/low-trust apps like those run via
>ClickOnce? :(

As soon as you don't have permissions to do interop, you're out of luck.

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Danny Tuppeny - 29 Sep 2005 18:39 GMT
>>Does this mean it can't be done with no/low-trust apps like those run via
>>ClickOnce? :(
>
> As soon as you don't have permissions to do interop, you're out of luck.

Doh!

I understand that some MS controls (like the treeview) work like this
anyway - is this just a case of "if microsoft wraps it, it doesn't need
interop permission"?
Oliver Sturm - 29 Sep 2005 19:24 GMT
>>>Does this mean it can't be done with no/low-trust apps like those run via
>>>ClickOnce? :(
[quoted text clipped - 6 lines]
>anyway - is this just a case of "if microsoft wraps it, it doesn't need
>interop permission"?

I don't know exactly what you're seeing with the TreeView, I don't
normally use it. I just had a quick look and I saw that the TreeView does
in fact have this line on its WndProc:

  [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)]

This is .NET 2, so it might have been changed from earlier versions - but
I would think the TreeView couldn't possibly work in an environment where
the UnmanagedCode permission is not granted.

Now, once the TreeView can actually be used, it's a common control - so
the code that calls into the imagelist APIs could be outside of the parts
we can see in .NET code. And this code would no longer be caught by the
.NET interop layer, either.

Finally, for the interop thing there's a special attribute called
SuppressUnmanagedCodeSecurityAttribute - guess what that one does... look
here (MSDN) for a discussion: http://shrinkster.com/8cx

And then, even more finally, nobody would keep you from implementing
similar functionality yourself, without using the imagelist API. This
would probably be a bit difficult as soon as you want the drag images to
be displayed while data is being dragged between controls (as opposed to
only above one control) - just the reason why MS chose to implement this
stuff in as unlikely a place as the imagelist API.

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Danny Tuppeny - 29 Sep 2005 19:57 GMT
> I don't know exactly what you're seeing with the TreeView, I don't
> normally use it
<snip>
> This is .NET 2, so it might have been changed from earlier versions - but
> I would think the TreeView couldn't possibly work in an environment where
> the UnmanagedCode permission is not granted.

That's what I thought, but not for the reason you gave. My original question
is answered on the page you posted, I understand the security a lot more.
However, you said:

>  I saw that the TreeView does in fact have this line on its WndProc:
> [SecurityPermission(SecurityAction.LinkDemand,
> Flags=SecurityPermissionFlag.UnmanagedCode)]

Now that confused me. For two reasons... One, I don't understand why it's
needed - surely the treeview is pretty safe?! Two - does this mean my
planned ClickOnce application can't use the TreeView?

Where did you get that info from? Is it based on the beta2 and could it
change? Or was it from msdn? :(

Danny
Oliver Sturm - 30 Sep 2005 10:10 GMT
>That's what I thought, but not for the reason you gave. My original
>question is answered on the page you posted, I understand the security a
[quoted text clipped - 7 lines]
>needed - surely the treeview is pretty safe?! Two - does this mean my
>planned ClickOnce application can't use the TreeView?

Probably the TreeView is pretty safe, but apparently they didn't see this
as a valid reason to work around .NET code security - which I generally
find a good thing.

I haven't tried this and I also haven't used ClickOnce, apart from a
cursory test. But I think you can actually run ClickOnce applications that
require all kinds of permissions client side; what I meant was you'll have
to make sure you have these permissions because the TreeView certainly
seems to require them. To acquire the needed permissions, you'll need to
use a feature called "permission elevation". Here's a blog article with a
quick explanation:
http://blogs.msdn.com/shawnfa/archive/2003/11/14/57031.aspx

But you can also find a lot of other docs, also on MSDN, by googling for
"permission elevation".

>Where did you get that info from? Is it based on the beta2 and could it
>change? Or was it from msdn? :(

This information is based on beta 2 and I got it by looking at the sources
for the TreeView with Reflector.

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Danny Tuppeny - 30 Sep 2005 18:25 GMT
> But I think you can actually run ClickOnce applications that require all
> kinds of permissions client side; what I meant was you'll have to make
> sure you have these permissions because the TreeView certainly seems to
> require them. To acquire the needed permissions, you'll need to use a
> feature called "permission elevation". Here's a blog article with a quick
> explanation: http://blogs.msdn.com/shawnfa/archive/2003/11/14/57031.aspx

That's right, but your user would get a box (I hope) saying something like
"this app wants to do something dangerous. Please click no" if I want access
for unmanaged code. The ActiveX dialog doesn't seem to put people off, so
I'm hoping with ClickOnce it's a bit more obvious just what you're giving
permission for!

Besides, even if I *can* get it, I don't want a user to have to give my app
access to do "anything" just for a treeview :-(

Anyways, I'll wait for the final release, and try it :-)

> This information is based on beta 2 and I got it by looking at the sources
> for the TreeView with Reflector.

Excellent - I was sure there was something out there, but I googled and
couldn't find it! Reflector it is! (duh, how obvious is that!)
:-)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.