hi all,
I have a treeview and the picturebox in the form. i have a tree view which have icons for each node. i have imagelist which loads icons for nodes in the treeview. some image will be loaded in the picturebox. the user has to drag and drop the icon from the treeview on to the image in the picturebox. when the form is closed, the icons that are dragged and dropped on to the image sud be save.the co-ordinates of the icons on the image sud be saved in a xml file.
i have tried the drap and drop from treeview. but it is not working. i have attached the code below. pls have a look at it and let me why its not working... pls help me to do this... -
// This part so you can drag to picture to the control...
-
private void pictureBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
-
{
-
if (e.Data.GetDataPresent(DataFormats.FileDrop))
-
e.Effect = DragDropEffects.Copy;
-
else
-
e.Effect = DragDropEffects.None;
-
}
-
-
// And now to load the picture in the picturebox control...
-
private void pictureBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
-
{
-
string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop);
-
pictureBox1.Image = Image.FromFile(filenames[0]);
-
}
-
-
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
-
{
-
isDragging = true;
-
currentX = e.X;
-
currentY = e.Y;
-
}
-
-
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
-
{
-
if (isDragging)
-
{
-
pictureBox1.Top = pictureBox1.Top + (e.Y - currentY);
-
pictureBox1.Left = pictureBox1.Left + (e.X - currentX);
-
}
-
}
-
-
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
-
{
-
isDragging = false;
-
}
-
-
//code to generate tree view
-
-
private void PopulateTreeView()
-
{
-
//string userpath;
-
//userpath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
-
//userpath += @"C:\\Documents and Settings\\chr6kor\\My Documents";
-
-
DirectoryInfo startFolder = new DirectoryInfo(@"C:\Documents and Settings\chr6kor\My Documents");
-
//DirectoryInfo startFolder = new DirectoryInfo(userpath);
-
TreeNode rootNode = treeView1.Nodes.Add(startFolder.Name, startFolder.Name,0,0);
-
-
CreateFileSystemNodes(rootNode, startFolder);
-
}
-
-
private void CreateFileSystemNodes(TreeNode currentNode, DirectoryInfo currentFolder)
-
{
-
-
// add all sub-folders within the current folder
-
-
foreach (DirectoryInfo subfolder in currentFolder.GetDirectories())
-
{
-
-
TreeNode subFolderNode = currentNode.Nodes.Add(subfolder.Name, subfolder.Name,1,1);
-
-
CreateFileSystemNodes(subFolderNode, subfolder);
-
-
}
-
-
// add the files within the folder
-
-
foreach (FileInfo file in currentFolder.GetFiles())
-
{
-
-
currentNode.Nodes.Add(file.Name, file.Name, 2, 2);
-
-
}
-
-
}
-
-
-
private string GetPathFromNode(TreeNode node)
-
{
-
if (node.Parent == null)
-
{
-
return node.Text;
-
}
-
return Path.Combine(GetPathFromNode(node.Parent), node.Text);
-
}
-
-
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
-
{
-
if (bitmap != null)
-
{
-
bitmap.Dispose();
-
}
-
try
-
{
-
string fileName = GetPathFromNode(e.Node);
-
bitmap = new Bitmap(fileName);
-
FileInfo f = new FileInfo(fileName);
-
if (bitmap.Width > bitmap.Height)
-
{
-
pictureBox1.Width = panel1.Width;
-
pictureBox1.Height =
-
(int)((double)bitmap.Height * panel1.Width / bitmap.Width);
-
}
-
else
-
{
-
pictureBox1.Height = panel1.Height;
-
pictureBox1.Width =
-
(int)((double)bitmap.Width * panel1.Height / bitmap.Height);
-
}
-
pictureBox1.Image = bitmap;
-
//this.Text = "pic" + f.Name;
-
}
-
catch
-
{
-
//pictureBox1.Width = panel1.Width;
-
//pictureBox1.Height = panel1.Height;
-
}
-
}
-
-
pls help me sort out the problem.
thanks a lot in advance.
regards
chaitra
7 4716
Is the AllowDrop property on the appropriate controls set to true?
That's the only thing I can think of outright, if that's not it can you describe how it's not working? Like, drag/drop doesn't work at all or are you getting unexpected behaviour?
hi Texmo,
there is no error actually.. but drag and drop is not working at all... dont know how to do..
Did you try setting the AllowDrop property to true?
yes i tried it.. but its still not working
Ok, I looked further into this. Apparently, even though a PictureBox has the drag and drop methods, it doesn't allow drag and drop... which is really strange because it's got the methods for it. I did some digging around and couldn't find a reason for it; however, others have encountered the same issue. http://social.msdn.microsoft.com/for...4-0af75de893fd
At that Microsoft link they recommend doing the drag/drop on the form, which may not suit your purposes. I copied/pasted the code you wrote into a new project and linked everything up. It seems as though your PictureBox is contained within a Panel, so I just enabled drag/drop on the panel and used the same events you already had created.
Everything worked perfectly :)
hello Texmo,
i dont want to drag the image. consider for examlpe, i have a treeview of c drive. all the folders and files in that will be displayed in the treeview. for each node, folder icon will be displayed, for each file some other icon (.ico extension) will be added and displayed connectin an image list to the treeview. once the tree view is displayed, the picturebox will contain some jpeg image. from the tree view i want to drag n drop that folder or some other icon in the treeview on to the jpeg image. that icon sud be placed on the image in the picturebox.
pls can u help me to do this.....
regards,
chaitra
I didn't say anything about dragging the image, I was talking about dragging to the image. The code you have set up, the drag and drop methods go on the image. The link I provided you says that this isn't possible, you have to put these methods on the Panel containing the PictureBox because, for whatever reason, Microsoft hasn't exposed the AllowDrop method on the PictureBox Object.
If it's just that you're unable to get the item to drag from the tree view, I think you're missing the call to DoDragDrop in the TreeView's ItemDrag event.
Read here for more information: http://support.microsoft.com/kb/307968 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Karsten Schramm |
last post by:
Hi,
if I drag an Outlook.MailItem to a Windows-Explorer window a
<subject>.msg file will be created.
Now I try to drag & drop a mail item to my own WinForm app.
Unfortunately it doesn't work....
|
by: Wiktor Zychla |
last post by:
today we've found a critical issue regarding the ListView from
Windows.Forms. it was confirmed on several machines with Win2K and XP.
here's the problem: create a ListView with about 50000 rows....
|
by: Qingdong Z. |
last post by:
I have a VS.NET windows application which use drag-drop feather. It works
fine when application start, but stops working after application run one or
two days. The application is related to Video...
|
by: Brett Romero |
last post by:
Is there an object similar to the treeview (or way to extend tree view)
that will allow drag/drop functionality to reorder child nodes? For
example:
Parent1
-c1
-c2
-c3
Drag c3 above c1:
|
by: Nick |
last post by:
Hi,
I am developping an app using managed C++. I want to be able to do a
drag drop from the app to windows explorer. The files to be dropped
onto explorer do not exist yet, the files are to be...
|
by: shinichi81 |
last post by:
Could anyone help me?
After updating icon for a drive, for example C drive by specifying icon file at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\C\DefaultIcon,...
|
by: murrayatuptowngallery |
last post by:
I would like to have a slider or mouse position click capture means of
collecting a user input from a scale or ruler-like graphic.
I found some code snippets for mouse position capture on...
|
by: Mukesh Agarwal |
last post by:
Hi,
I am developing a windows application, in which I am giving two options to the user for the file selection.
1. Open File Dialog
2. Drag/ Drop
Now I want that the user can Drag/Drop...
|
by: jakki |
last post by:
hi every one..
i am binding data in a tree view using windows C# .. auctually i finished most of the code.. but i did't know how to proceed further .. i attached the code hear.. as well as...
|
by: =?Utf-8?B?QW5kcmV3?= |
last post by:
I have some code that I use to drag and drop from treeview to treeview, now I
want to adapt the code to drag and drop from listview to treeview. I am
having problems adapting the code nor can I...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |