Image Converter

Okay here is what is going on. I can get it to convert all the file types thats no problem. The problem is I want it to open multiple pictures, show them in like a textbox or something, and also allow the user to chose which directory they are saved in. Also I want to have an option where all of them can be renamed by numbers no matter how many of them there are. What I really want is like two list boxes and the pictures in the directory the user has choosen will appear in the box on the left then the user has the option which ones they want and it tranfers them into the second box.....any ideas guys? :( I've googled and googled and I found nothing....heck I can't even get it to where the user picks the folder they want...

Comments

  • [b][red]This message was edited by Relman at 2004-11-14 13:52:41[/red][/b][hr]
    [b][blue]Added more references[/blue][/b]

    : Okay here is what is going on. I can get it to convert all the file types thats no problem. The problem is I want it to open multiple pictures, show them in like a textbox or something, and also allow the user to chose which directory they are saved in. Also I want to have an option where all of them can be renamed by numbers no matter how many of them there are. What I really want is like two list boxes and the pictures in the directory the user has choosen will appear in the box on the left then the user has the option which ones they want and it tranfers them into the second box.....any ideas guys? :( I've googled and googled and I found nothing....heck I can't even get it to where the user picks the folder they want...
    :
    I don't have my IDE in front of me, so all I can do is give you pointers on how to go about what you want to do. Here is what I did:

    I broke down your problem into the following controls:
    Treeview control - Display the directories (TreeView1)
    Listbox Control - Show picture files in a directory (ListBox1)
    Listbox Control - Show currently selected pictures (ListBox2)
    3 buttons - Add, Remove and Process (btnAdd, btnRemove, btnProcess)

    Look at this site to find out how to display directories: http://www.vbip.com/miscellaneous/directory-info/dir-info-01.asp

    Once you have done that, in the "AfterSelect" event, get the names of the picture files within the directory that is refered to by TreeView1.SelectedNode and fill your listbox with them (More on this later).

    The code to get the files in a directory is:
    [code]
    Function GetFiles(DirName as String) as FileInfo()
    [green]'Make a reference to the directory.[/green]
    Dim di As New DirectoryInfo(DirName)
    [green]'Get a reference to each file in that directory.[/green]
    Return di.GetFiles()
    End Function

    [green] 'To use the above function to
    'Display the names of the files, do the following:
    'Dim fri As FileInfo
    'For Each fri In GetFiles("C:")
    ' Console.WriteLine(fri.Name)
    'Next fri[/green]
    [/code]

    Now, lets look at btnAdd: This will add the value of the selected file in the listbox which shows the directories contents into the the listbox containing references to files that need to be processed. I'd suggest that you make a class that will contain the FullPath of the file as well as the files name so that you can add objects of the class to the listbox and it will display ony the files name, but when you click on btnProcess, it will be able to access the FullPath field. This is how it is done:
    [code]
    Class MyListItem
    [green]'Make it a public field becuase we don't need to do any validating[/green]
    Public FullPath as string
    [green]'Create a ToString method that overrides the default tostring method of an object.
    'This will return the string that is to be displayed by the Listbox
    'As I said, I don't have my IDE infront of me, but it will lok something like this[/green]
    Function ToString() as String
    [green]'In one line, I'm extracting for the files actual name from its fullpath.
    'What I want is all the charachters from the right of the string to the ""
    'So I reverse the string. Get a substring from the 1st charachter (which was the last)
    'to the position of the "". Then I reverse it again to get back to how I want it.[/green]
    Return FullPath.Reverse.Substring(1,Instr(FullPath.Reverse,"")-1).Reverse
    End Function

    Sub New(TheFullPath as string)
    TheFullpath = Fullpath
    End Sub
    End Class

    [green]'Later on in the code, where I want to add an item to the listbox I add it in the following way:[/green]
    ListBox2.Add(New MyListItem(TreeView1.SelectedNodes.FullPath & "" & ListBox1.SelectedItems(0)))
    [green]'That code is not 100% correct, but the point I'm making is the "New MyListItem".

    'And Later (eg. in the onclick event od btnProcess), when you want to find the full path do[/green]
    FullPath = CType(ListBox2.SelectedItems(0), MyListItem).FullPath
    [/code]

    As I've said twice already, I don't have my IDE in front of me. Therefore, most of this code is speculation. Also, you should also populate ListBox1 with the class by getting the fullpath from the DirectoryInfo Object, in the AfterSelect Event of the Treeview control.

    For More info on the Treeview Control, look at:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformstreeviewclasstopic.asp
    For the ListBox control Look at:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistboxclasstopic.asp
    For more information on file IO Look at:
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconworkingwithio.asp
    For more info on the Directory Info class look at:
    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIODirectoryInfoClassTopic.asp
    and its GetFiles method. (http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIODirectoryInfoClassGetFilesTopic1.asp)

    Here is a quote fom the MSDN library confirming part of the code that I wrote above: "When an object is being added to the ListBox, the control uses the text defined in the ToString method of the object unless a member name within the object is specified in the DisplayMember property. "

    I hope this helps you on your way to solving your problem,

    Akiva Kraines
  • : [b][red]This message was edited by Relman at 2004-11-14 13:52:41[/red][/b][hr]
    : [b][blue]Added more references[/blue][/b]
    :
    : : Okay here is what is going on. I can get it to convert all the file types thats no problem. The problem is I want it to open multiple pictures, show them in like a textbox or something, and also allow the user to chose which directory they are saved in. Also I want to have an option where all of them can be renamed by numbers no matter how many of them there are. What I really want is like two list boxes and the pictures in the directory the user has choosen will appear in the box on the left then the user has the option which ones they want and it tranfers them into the second box.....any ideas guys? :( I've googled and googled and I found nothing....heck I can't even get it to where the user picks the folder they want...
    : :
    : I don't have my IDE in front of me, so all I can do is give you pointers on how to go about what you want to do. Here is what I did:
    :
    : I broke down your problem into the following controls:
    : Treeview control - Display the directories (TreeView1)
    : Listbox Control - Show picture files in a directory (ListBox1)
    : Listbox Control - Show currently selected pictures (ListBox2)
    : 3 buttons - Add, Remove and Process (btnAdd, btnRemove, btnProcess)
    :
    : Look at this site to find out how to display directories: http://www.vbip.com/miscellaneous/directory-info/dir-info-01.asp
    :
    : Once you have done that, in the "AfterSelect" event, get the names of the picture files within the directory that is refered to by TreeView1.SelectedNode and fill your listbox with them (More on this later).
    :
    : The code to get the files in a directory is:
    : [code]
    : Function GetFiles(DirName as String) as FileInfo()
    : [green]'Make a reference to the directory.[/green]
    : Dim di As New DirectoryInfo(DirName)
    : [green]'Get a reference to each file in that directory.[/green]
    : Return di.GetFiles()
    : End Function
    :
    : [green] 'To use the above function to
    : 'Display the names of the files, do the following:
    : 'Dim fri As FileInfo
    : 'For Each fri In GetFiles("C:")
    : ' Console.WriteLine(fri.Name)
    : 'Next fri[/green]
    : [/code]
    :
    : Now, lets look at btnAdd: This will add the value of the selected file in the listbox which shows the directories contents into the the listbox containing references to files that need to be processed. I'd suggest that you make a class that will contain the FullPath of the file as well as the files name so that you can add objects of the class to the listbox and it will display ony the files name, but when you click on btnProcess, it will be able to access the FullPath field. This is how it is done:
    : [code]
    : Class MyListItem
    : [green]'Make it a public field becuase we don't need to do any validating[/green]
    : Public FullPath as string
    : [green]'Create a ToString method that overrides the default tostring method of an object.
    : 'This will return the string that is to be displayed by the Listbox
    : 'As I said, I don't have my IDE infront of me, but it will lok something like this[/green]
    : Function ToString() as String
    : [green]'In one line, I'm extracting for the files actual name from its fullpath.
    : 'What I want is all the charachters from the right of the string to the ""
    : 'So I reverse the string. Get a substring from the 1st charachter (which was the last)
    : 'to the position of the "". Then I reverse it again to get back to how I want it.[/green]
    : Return FullPath.Reverse.Substring(1,Instr(FullPath.Reverse,"")-1).Reverse
    : End Function
    :
    : Sub New(TheFullPath as string)
    : TheFullpath = Fullpath
    : End Sub
    : End Class
    :
    : [green]'Later on in the code, where I want to add an item to the listbox I add it in the following way:[/green]
    : ListBox2.Add(New MyListItem(TreeView1.SelectedNodes.FullPath & "" & ListBox1.SelectedItems(0)))
    : [green]'That code is not 100% correct, but the point I'm making is the "New MyListItem".
    :
    : 'And Later (eg. in the onclick event od btnProcess), when you want to find the full path do[/green]
    : FullPath = CType(ListBox2.SelectedItems(0), MyListItem).FullPath
    : [/code]
    :
    : As I've said twice already, I don't have my IDE in front of me. Therefore, most of this code is speculation. Also, you should also populate ListBox1 with the class by getting the fullpath from the DirectoryInfo Object, in the AfterSelect Event of the Treeview control.
    :
    : For More info on the Treeview Control, look at:
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformstreeviewclasstopic.asp
    : For the ListBox control Look at:
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistboxclasstopic.asp
    : For more information on file IO Look at:
    : http://msdn.microsoft.com/library/en-us/cpguide/html/cpconworkingwithio.asp
    : For more info on the Directory Info class look at:
    : http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIODirectoryInfoClassTopic.asp
    : and its GetFiles method. (http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIODirectoryInfoClassGetFilesTopic1.asp)
    :
    : Here is a quote fom the MSDN library confirming part of the code that I wrote above: "When an object is being added to the ListBox, the control uses the text defined in the ToString method of the object unless a member name within the object is specified in the DisplayMember property. "
    :
    : I hope this helps you on your way to solving your problem,
    :
    : Akiva Kraines
    :



    Okay I ran into some problems that I can't fix. I tried everything I could but I just can't fix them.

    -"Statement cannot appear within a method body. End of method assumed."

    Function GetFiles(DirName as String) as FileInfo()

    Class MyListItem



    -'Reverse' is not a member of 'String'.

    Return FullPath.Reverse.Substring(1, InStr(FullPath.Reverse, "") - 1).Reverse

    -Declaration expected.

    ListBox2.Add(New MyListItem(TreeView1.SelectedNodes.FullPath & "" & ListBox1.SelectedItems(0)))

    FullPath = CType(ListBox2.SelectedItems(0), MyListItem).FullPath

    DenKain
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories