Solved

change icon of drag treeview node

Posted on 2009-05-14
14
442 Views
Last Modified: 2012-05-07
i am using VS-2005 framework 2.0 how i can change the icon of draging node of tree on drag time and want to change icon conditionally and also icon should be same till destination tree node with mouse.  
0
Comment
Question by:farjack1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24393795
You would need to develop a Windows Shell Extension to acheive what you are trying to do. Microsoft recommends against developing Shell extensions in .NET. The favoured language is C++ and its a big project. so may be live with it!
0
 

Author Comment

by:farjack1
ID: 24394977
1 - can you send me link where microsoft is posted these comments.
2 - we can not do this thing in vb.net?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24395037
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:farjack1
ID: 24400049
Hi, i think maybe you did not understand my requirement.

1-  i want to drag tree node destination is other tree and its icon should be conditional
2-  when i will drop that node to destination tree on condition bases it mouse icon should be change
3 - Can i drag the same icon till destination node

this is my Q.

Thanks
 
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24400420
Do you want to use the custom icon or the default icon?
0
 

Author Comment

by:farjack1
ID: 24400432
i want to use my gif or icon files
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24400437
That's where you need to develop the shell extensions. I think you did not bother to read any of the articles. To show you own icon while dragging, you need to develop a shell extension. Check the last link and one of the templates is for drag icons.
0
 

Author Comment

by:farjack1
ID: 24400441
how we can use default icons?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24400453
lblTextSource1.DoDragDrop( lblTextSource1.Text, DragDropEffects.Copy)
lblTextSource1.DoDragDrop( lblTextSource1.Text, DragDropEffects.Move)
0
 

Author Comment

by:farjack1
ID: 24400461
i am draging tree node and droping on tree node  
0
 

Author Comment

by:farjack1
ID: 24400479
i want to change icon on detination tree as well
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24400556
0
 

Accepted Solution

by:
lkalvin earned 500 total points
ID: 24401338
I could be missreading your question but it sounds like you're asking how to change the cursor when dragging over a specific control?

Basically, if you have more than one control on your form where dragging can BEGIN, you'll want to have a different identifier used when you DoDragDrop:

Like:
myTextBox.DoDragDrop("Dragging From myTextBox", DragDropEffects.Copy)
-or-
myTreeNode.DoDragDrop("Dragging From myTreeNode", DragDropEffects.Copy)

And if the target of the dragging is another TreeNode - in THAT node you can examine the contents of e.Data.GetDataPresent(DataFormats.StringFormat) to see where you started from:

Sub myNewTreeNode_DragOver(...e as System.Windows.Forms.DragEventArgs)
   If e.Data.GetDataPresent(DataFormats.StringFormat) Then
      Dim DragString As String = e.Data.GetDataPresent(DataFormats.StringFormat)
      Select Case DragString
         Case "Dragging From myTextBox"
             ' You know the drag came FROM myTextBox

         Case "Dragging From myTreeNode"
             ' You know the drag came FROM myTreeNode
         Case Else
      End Select
   End If
End Sub

This is (of course) PSEUDO CODE but there's very little missing - check out the Attached Code Snippet for a more detailed example of altering the cursor.


Private _Dragging As Boolean = False	' If True = Dragging has begun
 
Private Sub MyTreeNode_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyTreeNode.MouseDown
	_Dragging = True
End Sub
 
Private Sub MyTreeNode_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyTreeNode.MouseMove
	If _Dragging Then
		MyTreeNode.DoDragDrop("Some Text to Identify WHAT is being draggged", DragDropEffects.Copy)
	End If
	_Dragging = False
End Sub
 
Private Sub MyTreeNode_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyTreeNode.DragOver
	If e.Data.GetDataPresent(DataFormats.StringFormat) Then
		e.Effect = DragDropEffects.None
	End If
End Sub
 
Private Sub MyTreeNode_GiveFeedback(ByVal sender As Object, ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles MyTreeNode.GiveFeedback
	e.UseDefaultCursors = False
 
	If ((e.Effect And DragDropEffects.Copy) = DragDropEffects.Copy) Then
		Dim CustomCursor As Cursor = GetCustomCursor(0)
		Cursor.Current = CustomCursor
	Else
		Dim CustomCursor As Cursor = GetCustomCursor(1)
		Cursor.Current = CustomCursor
	End If
End Sub
 
Private Function GetCustomCursor(ByVal CursorType As Integer) As Cursor
	Dim myCursor as Cursor
	
	Select Case CursorType
		Case 0
			myCursor = *someDragcursor* ' Whatever you want your Drag-Drop cursor to be
			
		Case 1
			myCursor = *someBadcursor* ' Whatever you want your Drag-Drop cursor to be
 
		Case Else
			myCursor = *someDefaultcursor* ' Whatever you want your Drag-Drop cursor to be
	End Select
	
	Return myCursor
End Function

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24438793
BRILLIANT. So you do not know the difference between icon and cursor!!!
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question