locked
On Image Click, Reading and writing to textbox RRS feed

  • Question

  • Hi,
    I have a panel that has two buttons (load and unload), when the user clicks the load button an OpenFileDialog allows them to chose any number of (up-to 24) images that will simply populate the Picturebox's on that panel.

    When they click one of these images/PictureBox's the image name is then written to a RichTextBox

    This is the code i am using to write the file names:
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            If TypeOf sender Is PictureBox Then
                Dim pb As PictureBox = CType(sender, PictureBox)
    
                Dim folder As String = IO.Path.GetDirectoryName(pb.ImageLocation)
    
                If Not String.IsNullOrEmpty(folder) AndAlso Not String.IsNullOrWhiteSpace(folder) AndAlso folder.Contains("\") Then
                    RTSpotBox.SelectedText = folder.Substring(folder.LastIndexOf("\") + 1) & "/" & IO.Path.GetFileName(pb.ImageLocation)
                End If
            End If
        End Sub

    I have a second panel identical to the First, except now, when the user clicks the load button a specific path is opened (C:\MyFolder\MySubFolder where they can still chose any number of images that will also populate the Picturebox's on that panel. In this same path there is also a text file with the same name as each of the images (EX: MyThing.jpg and MyThing.txt etc etc). When the user clicks one of the newly displayed images/PictureBox's on the panel i need it to read the text from the text file that has the same name and display the contents into the RichTextBox.

    If anyone understands what i am trying to achieve i'd really appreciate your help.


    regards Flatland France

    Tuesday, July 25, 2017 3:19 PM

Answers

  • Eyeman, 

    It was probably to late yesterday.

    Here the new code, now tested. 

    Public Class Form1
        Private WithEvents OpenFileDialog3 As New OpenFileDialog
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PicBox1.Click, PicBox2.Click, PicBox3.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RichTextBox1.SelectedText = IO.File.ReadAllText(IO.Path.GetDirectoryName(pb.ImageLocation) &
                                                            "\" &
                                                            IO.Path.GetFileNameWithoutExtension(pb.ImageLocation) &
                                                            ".txt")
        End Sub
        Private Sub ButtonLoadMyBlocks_Click(sender As Object, e As EventArgs) Handles Button1.Click
            OpenFileDialog3.Multiselect = True
            OpenFileDialog3.Title = "Select Image to Import"
            OpenFileDialog3.Filter = "Image Files (JPG)|*.jpg"
            If OpenFileDialog3.ShowDialog() = DialogResult.OK Then
                Dim PicBox() = {PicBox1, PicBox2, PicBox3}
                For Each s As String In Me.OpenFileDialog3.FileNames
                    Dim nextPicBox = PicBox.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
                    If Not IsNothing(nextPicBox) Then
                        nextPicBox.ImageLocation = s
                        nextPicBox.Refresh()
                    End If
                Next
            End If
        End Sub
    End Class

    I misinterpreted the text on MSDN about the fulname (while I knew it). It is the filename plus extension. 


    Success
    Cor

    Wednesday, July 26, 2017 9:09 AM
  • Eyeman, 

    It was probably to late yesterday.

    Here the new code, now tested. 

    Public Class Form1
        Private WithEvents OpenFileDialog3 As New OpenFileDialog
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PicBox1.Click, PicBox2.Click, PicBox3.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RichTextBox1.SelectedText = IO.File.ReadAllText(IO.Path.GetDirectoryName(pb.ImageLocation) &
                                                            "\" &
                                                            IO.Path.GetFileNameWithoutExtension(pb.ImageLocation) &
                                                            ".txt")
        End Sub
        Private Sub ButtonLoadMyBlocks_Click(sender As Object, e As EventArgs) Handles Button1.Click
            OpenFileDialog3.Multiselect = True
            OpenFileDialog3.Title = "Select Image to Import"
            OpenFileDialog3.Filter = "Image Files (JPG)|*.jpg"
            If OpenFileDialog3.ShowDialog() = DialogResult.OK Then
                Dim PicBox() = {PicBox1, PicBox2, PicBox3}
                For Each s As String In Me.OpenFileDialog3.FileNames
                    Dim nextPicBox = PicBox.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
                    If Not IsNothing(nextPicBox) Then
                        nextPicBox.ImageLocation = s
                        nextPicBox.Refresh()
                    End If
                Next
            End If
        End Sub
    End Class

    I misinterpreted the text on MSDN about the fulname (while I knew it). It is the filename plus extension. 


    Success
    Cor


    This did the trick, thank you very much for your time and effort.
    I obviously had to play around with naming to get it to run, and i also had to omit this part:
        Private WithEvents OpenFileDialog3 As New OpenFileDialog
    For some reason it didn't like that and spat an error at me about the Opendialog already being declared, But it works now after 2 days of headache :D
    Each picture box now finds it's partner txt file and displays the info in the RTB

    Thanks again Cor, Your a diamond

    regards Flatland France

    Wednesday, July 26, 2017 9:48 AM

All replies

  • Get the path and filename without the extension (jpg I presume), and attach ".txt" to it.

    Something like:

    ' Transform the name extension
      Dim strTextFile As String = Path.GetFileNameWithoutExtension(pb.ImageLocation) & ".txt"

    • Proposed as answer by Cor Ligthert Tuesday, July 25, 2017 5:12 PM
    • Unproposed as answer by Cor Ligthert Tuesday, July 25, 2017 11:57 PM
    Tuesday, July 25, 2017 3:37 PM
  • Hi Cyrille,
    That almost did the trick. With a bit of fiddling i managed to get it to display the name with the .txt extension.
    What i am actually trying to do is get it to read the contents of that file.txt and write them to the RichTextBox and not the name.

    I'll keep fiddling trying to understand what i don't understand :D

    regards Flatland France

    Tuesday, July 25, 2017 5:18 PM
  • Using the answer from Cyrille to verify if we really understand you

        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RTSpotBox.SelectedText = Path.GetFileNameWithoutExtension(pb.ImageLocation) & ".txt"
        End Sub
    Be aware that you use far to much code. My only doubt is about the property SelectedText


    Success
    Cor

    Tuesday, July 25, 2017 5:21 PM
  • Using the answer from Cyrille to verify if we really understand you

        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RTSpotBox.SelectedText = Path.GetFileNameWithoutExtension(pb.ImageLocation) & ".txt"
        End Sub
    Be aware that you use far to much code. My only doubt is about the property SelectedText


    Success
    Cor


    IO.Path also has a .ChangeExtension method. That would be even less code.

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, July 25, 2017 5:29 PM
  • Thanks for helping me reduce the code (i can go over other parts).

    This is giving me the same result. I am seeing the name.txt of the file in the RichTextBox. I am not seeing the contents of that name.txt file in the RichTextBox

    I have no difficulty calling the info from a resource.name.txt file using...

    RTSpotBox.SelectedText = My.Resources.columnTXT


    regards Flatland France

    Tuesday, July 25, 2017 5:45 PM
  • Thanks for helping me reduce the code (i can go over other parts).

    This is giving me the same result. I am seeing the name.txt of the file in the RichTextBox. I am not seeing the contents of that name.txt file in the RichTextBox

    I have no difficulty calling the info from a resource.name.txt file using...

    RTSpotBox.SelectedText = My.Resources.columnTXT


    regards Flatland France

    Please make it obvious who you're talking to.

    I haven't read all of this post, but do I understand that you have a text file to load?

    If so, a RichTextBox has a .LoadFile method. Be sure to test that the file exists first though.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, July 25, 2017 5:50 PM
  • Frank i didn't even realize you had joined the conversation

    I just saw answers and tried to understand and get my project working, came back answered and carried on.

    I apologize for going to fast and not reading through from start to finish, get a better understanding of what is being talked about and just throwing info in any old how. I guess that's how it gets confusing and you ruin a thread.


    regards Flatland France

    Tuesday, July 25, 2017 5:59 PM
  • Frank i didn't even realize you had joined the conversation

    I just saw answers and tried to understand and get my project working, came back answered and carried on.

    I apologize for going to fast and not reading through from start to finish, get a better understanding of what is being talked about and just throwing info in any old how. I guess that's how it gets confusing and you ruin a thread.


    regards Flatland France


    It happens. :)

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, July 25, 2017 6:01 PM
  • Using the answer from Cyrille to verify if we really understand you

        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RTSpotBox.SelectedText = Path.GetFileNameWithoutExtension(pb.ImageLocation) & ".txt"
        End Sub
    Be aware that you use far to much code. My only doubt is about the property SelectedText


    Success
    Cor

    Hi Cor
    As i realized others are answering and i am getting a little lost......
    Thanks for helping me reduce the code, but as i mentioned, it only displays the name.txt file and not it's contents.

    The SelectedText is making the difference between showing the results from one picture box click and another. Just Text will always show the same name.txt what ever Image/picturebox i click on.


    regards Flatland France

    Tuesday, July 25, 2017 6:09 PM
  • Sorry, I tried in fact to show more in detail how cyrille did mean it. 

    The sentence had to be

        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RTSpotBox.SelectedText = IO.File.ReadAllText(Path.GetFileNameWithoutExtension(pb.ImageLocation) & ".txt")
        End Sub


    Success
    Cor

    Tuesday, July 25, 2017 9:59 PM
  • Sorry, I tried in fact to show more in detail how cyrille did mean it. 

    The sentence had to be

        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RTSpotBox.SelectedText = IO.File.ReadAllText(Path.GetFileNameWithoutExtension(pb.ImageLocation) & ".txt")
        End Sub


    Success
    Cor

    I have been playing with this for hours now and can't implement it.
    Using your code i get and exception.
    Telling me that the Name.txt file can't be found in the bin/debug and that is not where it should be looking!??? The file it should be reading is where it should be, in the C:\MyFolder\MySubFolder
    This is driving me nuts. :D

    regards Flatland France

    Tuesday, July 25, 2017 11:15 PM
  • Flatland,

    I've not really been following this, but can you summarize your task here?

    Would the .Tag property of a PictureBox help or am I off-track?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Proposed as answer by Cor Ligthert Tuesday, July 25, 2017 11:57 PM
    • Unproposed as answer by Cor Ligthert Wednesday, July 26, 2017 9:09 AM
    Tuesday, July 25, 2017 11:19 PM
  • Flatland, 

    I think that I simply did misread the imagelocation property. After rereading it I see that it is only the path. 

    If you wait a little bit I make other code for you based on what Frank wrote about the tag property in the Picturebox. 


    Success
    Cor

    Tuesday, July 25, 2017 11:38 PM
  • Where you put the image in the 24 pictureboxes you add also

    PicturexBoxX.Tag = OFD.Filename 

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.tag(v=vs.110).aspx

    The code change is few

     Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RTSpotBox.SelectedText = IO.File.ReadAllText(IO.Path.GetFileNameWithoutExtension(CStr(pb.Tag)) & ".txt")
        End Sub


    Success
    Cor

    Tuesday, July 25, 2017 11:46 PM
  • Flatland,

    I've not really been following this, but can you summarize your task here?

    Would the .Tag property of a PictureBox help or am I off-track?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    I have a RichTextEditor, there are panels to choose things from on both the left and right hand sides of the main RichTextBox.
    On the menustrip tools section there is a small editor that allows the user to create new objects. When they have finished building a new object and chosen a jpg image to represent it in the main editor. that object and image are automatically saved based on the object name. If the objects name is "HAPPY" then it will be saved as HAPPY.txt and in the same folder the chosen image will be saved as HAPPY.jpg. (no matter what it's original name was).
    Going back to the main editor and using that newley built object from the right hand panel.
    That right hand panel as mentioned in my original post, has two button load and unload.
    When the user clciks the load button it will open the same folder that the obejcts and jpg image are automatically saved to. Only the jpgs are visible, the user can select from 1 to 24 of his/hers homemade objects by selecting from those images. they will populate the pictureboxs in the righthand panel.

    What i need is when one of the images in the panel is clicked the corresponding text file is then read and written to the main RichTextBox
    Because i don't know what the users created and how they named them, the editor needs to decide.
    Everything is in place and everything works except this last button click.

    By playing with the code i can get it to display the HAPPY.jpg name n the RTB and the HAPPY.txt name in the RTB, i just can't get it to write the code from the users HAPPY.txt file to the RTB.

    WOW, that's a lot at this time in the morning. I hope you or someone else can get the idea!


    regards Flatland France

    Tuesday, July 25, 2017 11:57 PM


  • WOW, that's a lot at this time in the morning. I hope you or someone else can get the idea!


    regards Flatland France

    I'm in the U.S. (CDT) so obviously we're not in the same locale. ;-)

    *****

    I glanced at what you wrote there because I'm signing off, but it sounds like you might want to consider your own class(es) here. Maybe not, but with your own you can have it work like you want to.

    Food for thought. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Wednesday, July 26, 2017 12:05 AM
  • Where you put the image in the 24 pictureboxes you add also

    PicturexBoxX.Tag = OFD.Filename 

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.tag(v=vs.110).aspx

    The code change is few

     Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox20.Click, PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox3.Click, PictureBox2.Click, PictureBox1.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RTSpotBox.SelectedText = IO.File.ReadAllText(IO.Path.GetFileNameWithoutExtension(CStr(pb.Tag)) & ".txt")
        End Sub


    Success
    Cor

    This is the code i am using to populate the PictureBox's (only 3 in this example)

       Private Sub ButtonLoadMyBlocks_Click(sender As Object, e As EventArgs) Handles ButtonLoadMyBlocks.Click
            OpenFileDialog3.Multiselect = True
            OpenFileDialog3.Title = "Select Image to Import"
            OpenFileDialog3.Filter = "Image Files (JPG)|*.jpg"
            If OpenFileDialog3.ShowDialog() = DialogResult.OK Then
                Dim PicBox2() As PictureBox = {PicBox01, PicBox02, PicBox03}
                For Each s As String In Me.OpenFileDialog3.FileNames
                    Dim nextPicBox = PicBox2.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
                    If Not IsNothing(nextPicBox) Then
                        nextPicBox.ImageLocation = s
                        nextPicBox.Refresh()
                    End If
                Next
            End If
        End Sub
    Where do i add the code you posted?

    PicturexBoxX.Tag = OFD.Filename

    I thought it maybe this:
    PictBox01.Tag = OFD.Filename, PictBox02.Tag = OFD.Filename, PictBox03.Tag = OFD.Filename,

    but that as with other tests, just didn't work, i couldn't figure it out.

    Time for some Zzd's


    regards Flatland France

    Wednesday, July 26, 2017 12:45 AM
  • Eyeman, 

    It was probably to late yesterday.

    Here the new code, now tested. 

    Public Class Form1
        Private WithEvents OpenFileDialog3 As New OpenFileDialog
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PicBox1.Click, PicBox2.Click, PicBox3.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RichTextBox1.SelectedText = IO.File.ReadAllText(IO.Path.GetDirectoryName(pb.ImageLocation) &
                                                            "\" &
                                                            IO.Path.GetFileNameWithoutExtension(pb.ImageLocation) &
                                                            ".txt")
        End Sub
        Private Sub ButtonLoadMyBlocks_Click(sender As Object, e As EventArgs) Handles Button1.Click
            OpenFileDialog3.Multiselect = True
            OpenFileDialog3.Title = "Select Image to Import"
            OpenFileDialog3.Filter = "Image Files (JPG)|*.jpg"
            If OpenFileDialog3.ShowDialog() = DialogResult.OK Then
                Dim PicBox() = {PicBox1, PicBox2, PicBox3}
                For Each s As String In Me.OpenFileDialog3.FileNames
                    Dim nextPicBox = PicBox.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
                    If Not IsNothing(nextPicBox) Then
                        nextPicBox.ImageLocation = s
                        nextPicBox.Refresh()
                    End If
                Next
            End If
        End Sub
    End Class

    I misinterpreted the text on MSDN about the fulname (while I knew it). It is the filename plus extension. 


    Success
    Cor

    Wednesday, July 26, 2017 9:09 AM
  • Eyeman, 

    It was probably to late yesterday.

    Here the new code, now tested. 

    Public Class Form1
        Private WithEvents OpenFileDialog3 As New OpenFileDialog
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PicBox1.Click, PicBox2.Click, PicBox3.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RichTextBox1.SelectedText = IO.File.ReadAllText(IO.Path.GetDirectoryName(pb.ImageLocation) &
                                                            "\" &
                                                            IO.Path.GetFileNameWithoutExtension(pb.ImageLocation) &
                                                            ".txt")
        End Sub
        Private Sub ButtonLoadMyBlocks_Click(sender As Object, e As EventArgs) Handles Button1.Click
            OpenFileDialog3.Multiselect = True
            OpenFileDialog3.Title = "Select Image to Import"
            OpenFileDialog3.Filter = "Image Files (JPG)|*.jpg"
            If OpenFileDialog3.ShowDialog() = DialogResult.OK Then
                Dim PicBox() = {PicBox1, PicBox2, PicBox3}
                For Each s As String In Me.OpenFileDialog3.FileNames
                    Dim nextPicBox = PicBox.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
                    If Not IsNothing(nextPicBox) Then
                        nextPicBox.ImageLocation = s
                        nextPicBox.Refresh()
                    End If
                Next
            End If
        End Sub
    End Class

    I misinterpreted the text on MSDN about the fulname (while I knew it). It is the filename plus extension. 


    Success
    Cor


    This did the trick, thank you very much for your time and effort.
    I obviously had to play around with naming to get it to run, and i also had to omit this part:
        Private WithEvents OpenFileDialog3 As New OpenFileDialog
    For some reason it didn't like that and spat an error at me about the Opendialog already being declared, But it works now after 2 days of headache :D
    Each picture box now finds it's partner txt file and displays the info in the RTB

    Thanks again Cor, Your a diamond

    regards Flatland France

    Wednesday, July 26, 2017 9:48 AM
  • Eyeman, 

    It was probably to late yesterday.

    Here the new code, now tested. 

    Public Class Form1
        Private WithEvents OpenFileDialog3 As New OpenFileDialog
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PicBox1.Click, PicBox2.Click, PicBox3.Click
            Dim pb As PictureBox = DirectCast(sender, PictureBox)
            RichTextBox1.SelectedText = IO.File.ReadAllText(IO.Path.GetDirectoryName(pb.ImageLocation) &
                                                            "\" &
                                                            IO.Path.GetFileNameWithoutExtension(pb.ImageLocation) &
                                                            ".txt")
        End Sub
        Private Sub ButtonLoadMyBlocks_Click(sender As Object, e As EventArgs) Handles Button1.Click
            OpenFileDialog3.Multiselect = True
            OpenFileDialog3.Title = "Select Image to Import"
            OpenFileDialog3.Filter = "Image Files (JPG)|*.jpg"
            If OpenFileDialog3.ShowDialog() = DialogResult.OK Then
                Dim PicBox() = {PicBox1, PicBox2, PicBox3}
                For Each s As String In Me.OpenFileDialog3.FileNames
                    Dim nextPicBox = PicBox.Where(Function(x) IsNothing(x.Image)).FirstOrDefault
                    If Not IsNothing(nextPicBox) Then
                        nextPicBox.ImageLocation = s
                        nextPicBox.Refresh()
                    End If
                Next
            End If
        End Sub
    End Class

    I misinterpreted the text on MSDN about the fulname (while I knew it). It is the filename plus extension. 


    Success
    Cor


    Finally i have found an issue with this that i can't resolve, i discovered by accident that when i click the panel that holds the pictureboxs it causes my app to crash. Luckily i found it then, because i discovered it on a release version, just before, uploading to the net :D

    This line seems to be the culprite:

            RTSpotBox.SelectedText = IO.File.ReadAllText(IO.Path.GetDirectoryName(pb.ImageLocation) & "\" & IO.Path.GetFileNameWithoutExtension(pb.ImageLocation) & ".txt")

    It throws an exception that i don't understand

    Apart from that it works as it should.


    regards Flatland France


    • Edited by EyeMan Android Thursday, July 27, 2017 3:39 PM missing text
    Thursday, July 27, 2017 3:37 PM
  • Flatland,

    Can you explain (and/or show screenshots) what your program is and does? If you're open for a different way to do this then I may can help.

    I won't promise anything until I know what I'm in for though. ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, July 27, 2017 4:52 PM
  • Flatland,

    Can you explain (and/or show screenshots) what your program is and does? If you're open for a different way to do this then I may can help.

    I won't promise anything until I know what I'm in for though. ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    So far you have told me to make it obvious who i am talking to, in 2 different replies you have said
    1) you haven't read everything and
    2) you are not following the conversation. And asked for a summary, which i gave as a lengthy reply.

    Now you are asking me to explain (again) with screen shots so you can see what i am doing, just in case i am open to doing things differently, but that said you are not sure what you would be letting yourself into. So i could still be wasting my time writing and posting.
    As for being helpful you have posted this so far:
    Would the .Tag property of a PictureBox help or am I off-track?

    Maybe you should go back to my opening post and read the whole thing through and maybe more than once until you understand it and are able to follow. then go over the second lengthy post i gave you as a personal reply until you understand that as well, then you can say you have read, are following and understand. if after that you have no better suggestion than maybe '.tag' i really can't see the point in showing you images and explaing myself again just for you. TRY READING

    regards Flatland France

    Thursday, July 27, 2017 6:14 PM
  • Flatland,

    Can you explain (and/or show screenshots) what your program is and does? If you're open for a different way to do this then I may can help.

    I won't promise anything until I know what I'm in for though. ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    So far you have told me to make it obvious who i am talking to, in 2 different replies you have said
    1) you haven't read everything and
    2) you are not following the conversation. And asked for a summary, which i gave as a lengthy reply.

    Now you are asking me to explain (again) with screen shots so you can see what i am doing, just in case i am open to doing things differently, but that said you are not sure what you would be letting yourself into. So i could still be wasting my time writing and posting.
    As for being helpful you have posted this so far:
    Would the .Tag property of a PictureBox help or am I off-track?

    Maybe you should go back to my opening post and read the whole thing through and maybe more than once until you understand it and are able to follow. then go over the second lengthy post i gave you as a personal reply until you understand that as well, then you can say you have read, are following and understand. if after that you have no better suggestion than maybe '.tag' i really can't see the point in showing you images and explaing myself again just for you. TRY READING

    regards Flatland France

    Best of luck.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, July 27, 2017 6:17 PM
  • Thanks for the help anyway.


    regards EyeMan Android

    Thursday, July 27, 2017 11:21 PM
  • Thanks for the help anyway.


    regards EyeMan Android

    If you're addressing me (no, I really can't tell) and you really do want help here, then don't belittle the people trying to help here -- me.

    Is that fair?

    If you want to wait for your "diamond" to help then by all means -- be patient and I'll back out of this whole thing.

    *****

    When you first posted this, I was having computer hardware problems and yesterday I was out pretty much all day.

    I saw your reply to Cor and assumed you had it all sorted but obviously not.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, July 27, 2017 11:27 PM
  • Thanks for the help anyway.


    regards EyeMan Android

    If you're addressing me (no, I really can't tell) and you really do want help here, then don't belittle the people trying to help here -- me.

    Is that fair?

    If you want to wait for your "diamond" to help then by all means -- be patient and I'll back out of this whole thing.

    *****

    When you first posted this, I was having computer hardware problems and yesterday I was out pretty much all day.

    I saw your reply to Cor and assumed you had it all sorted but obviously not.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    I have reported you, your participation in this thread has done nothing but ruin it.

    You say your not reading, not following, propose nothing, now you have hardware problems and was out for the day. And you say i belittle you. maybe you should read first before opening it and also keep your personal problems to yourself, i don't care if you go out for the day or not.
    Why did you even bother joining the conversation? Just to bring it down? I have posted info for you and still you haven't read it. And you insist on even more info. What is it that you haven't understood exactly.
    You need to calm down and only join a thread if you have something worth proposing, instead of just giving orders.
    Maybe i should back off, because after you said, wait for my diamond (me belittling/condescending), i am wondering if you are not just a kid, maybe about 14 or 15 years old. Because your whole effort and reaction here has been a complete and utter waste of time.



    regards EyeMan Android

    Friday, July 28, 2017 8:31 AM
  • ...i am wondering if you are not just a kid, maybe about 14 or 15 years old.

    I wish I were.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Friday, July 28, 2017 8:51 AM