I have statically created a TreeView with the TreeNode Editor.
Is it possible that when a node is selected to display an image within a picturebox?
Im having difficulty with this relationship.
Thanks in Advance
TreeView Help
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: TreeView Help
It is not possible to understand what you are trying to ask. I recommend starting by reviewing the articles in this link to gain some understanding of how to work with forms and controls then try and ask your question again.
https://info.sapien.com/index.php/guis/ ... nistrators
https://info.sapien.com/index.php/guis/ ... nistrators
Re: TreeView Help
This Function Loads the tree in my form
This event opens a folder in tree. The files in the folder(s) have .png image. When a user selects a file(img) in folder, I'd like the picturebox to display that image from that path($_.Node.ToolTipText)..
Thank you
- function Load-FolderIntoTree
- {
- param([System.Windows.Forms.TreeView]$TreeView, [string]$Directory)
- #Disable Drawing
- $TreeView.BeginUpdate()
- $TreeView.Nodes.Clear()
- $folderName = [System.IO.Path]::GetFileName($Directory)
- $root = $TreeView.Nodes.Add($folderName, $folderName, 1, 1)
- $root.ToolTipText = $Directory
- $subfolders = [System.IO.Directory]::GetDirectories($Directory)
- if(-not $script:HideSubFolders)
- {
- foreach($folder in $subfolders)
- {
- $folderName = [System.IO.Path]::GetFileName($folder)
- $node = $root.Nodes.Add($folderName, $folderName, 1, 1)
- $node.ToolTipText = $folder
- }
- }
- $files = [System.IO.Directory]::GetFiles($Directory)
- foreach($file in $files)
- {
- $fileName = [System.IO.Path]::GetFileName($file)
- $node = $root.Nodes.Add($fileName, $fileName, 0, 0)
- $node.ToolTipText = $file
- }
- $root.Expand()
- #Enable Drawing
- $treeview1.EndUpdate()
- }
- $treeview1_NodeMouseDoubleClick=[System.Windows.Forms.TreeNodeMouseClickEventHandler]{
- #Event Argument: $_ = [System.Windows.Forms.TreeNodeMouseClickEventArgs]
- if($_.Node.ImageIndex -eq 1)
- {
- #Folder - Open it
- Load-FolderIntoTree -TreeView $treeview1 -Directory $_.Node.ToolTipText
- #Open img to picturebox
- $picturebox1.image = $_.Node.ToolTipText ##<--This is where I get lost.
- }
- }
Re: TreeView Help
I still cannot understand what you are asking. Tree nodes have an image property. Please look at the documentation to see how to use the image property and how to display and hide images. You cannot just add a PictureBox to a tree control.
If you are asking how to load an image file into a PictureBox then look at the control reference and it will show you how to do this.
If you are asking how to load an image file into a PictureBox then look at the control reference and it will show you how to do this.
Re: TreeView Help
O You mean like this, right?
$picturebox1.image = [System.Drawing.Image]::FromFile($treeview.selectednode.fullpath)
but I get this error- Exception calling "FromFile" with "1" argument(s): "The path is not of a legal form."
$picturebox1.image = [System.Drawing.Image]::FromFile($treeview.selectednode.fullpath)
but I get this error- Exception calling "FromFile" with "1" argument(s): "The path is not of a legal form."
Re: TreeView Help
The node path and path of desired image are the same.
Thanks for help, I will keep working on this task.
Thanks for help, I will keep working on this task.
Re: TreeView Help
Here is an old sampler I built a few years ago. It will help you understand how to navigate and reference nodes in a tree.
- Attachments
-
- Demo-TreeviewFolders.psf
- (31.47 KiB) Downloaded 91 times