• 0

Show text readme with choice from listbox


Question

Im self educated on visual basic programming. so its basically a learning curve.

 

but need help with something.

 

 

using visual studio 2013 with visual basic net

 

working on map loader for a pc game.

 

there is a txt file with credits and info in the same directory as the maps.

 

so far I have a listbox that scans the directory and shows all the map files and then user selects the map and then clicks a start button and it loads the game with the map. 

 

but I also want to a have a txt box for the map selected showing the information for the map.

 

so what I want to do is when a user clicks on a map in the listbox,it will show a preview of the maps txt file in a separate box on the form.

6 answers to this question

Recommended Posts

  • 0

If your description files have the same name as the maps other than the extension you could just use System.IO.Path.ChangeExtension to create the file name of the text object then load it with File.ReadAllText

 

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        If ListBox1.SelectedItem IsNot Nothing And TypeOf ListBox1.SelectedItem Is String Then
            Dim selectedMap As Object = ListBox1.SelectedItem
            Dim mapDescriptionFile As String = Path.ChangeExtension(selectedMap, "txt")
            If File.Exists(mapDescriptionFile) Then
                TextBox1.Text = File.ReadAllText(mapDescriptionFile)
            End If
        End If
    End Sub
If they're not the same you can either build a dictionary with the map filename as the key and description filename as the value. Or if you want to be lazy you can use a ListView instead and set the Tag property to the description filename. :)

 

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedItems IsNot Nothing And TypeOf ListView1.SelectedItems(0).Tag Is String Then
            Dim selectedMap As ListViewItem = ListView1.SelectedItems(0)
            Dim mapDescriptionFile As String = selectedMap.Tag

            If File.Exists(mapDescriptionFile) Then
                TextBox1.Text = File.ReadAllText(mapDescriptionFile)
            End If
        End If
    End Sub
(The second example assumes that you have set the ListView's MultiSelect property to False since you would only want to display the description for one map at a time.)
  • 0
  On 30/07/2014 at 03:28, dsbig said:

Im self educated on visual basic programming. so its basically a learning curve.

 

but need help with something.

 

 

using visual studio 2013 with visual basic net

 

working on map loader for a pc game.

 

there is a txt file with credits and info in the same directory as the maps.

 

so far I have a listbox that scans the directory and shows all the map files and then user selects the map and then clicks a start button and it loads the game with the map. 

 

but I also want to a have a txt box for the map selected showing the information for the map.

 

so what I want to do is when a user clicks on a map in the listbox,it will show a preview of the maps txt file in a separate box on the form.

 

Hi,

 

I am trying to help you as much as I can but from the looks of your program you want to show a preview of the map, correct? Are you trying to show a Picture of your map or anything else?

 

Normally, you would use the Drawing class to display images on a container or a datagrid. Quickest way would be to add a .NET label on your application, and when the user selects a map you fire an event to load a .bmp file from a specific location.

 

Private Sub CreateMyLabel()

    ' Create a new label and bitmap. 

    Dim Label1 As New Label()
    Dim Image1 As Image

    Image1 = Image.FromFile("c:\\MyImage.bmp")


    ' Set the size of the label to accommodate the bitmap size.

    Label1.Size = Image1.Size        

    ' Initialize the label control's Image property.

    Label1.Image = Image1

    ' ...Code to add the control to the form... 

End Sub
  • 0

I have a listbox  that scans a folder for *.map files and shows a list of maps in the listbox.

 

and there is also a txt file that has credit and also information that folder.

 

when clicking a map title in the listbox. a textbox will show the information for that map.

 

 

list of maps

 

listbox_zps008f2eea.png

 

when someone select a map then it would show the matching .txt file with the information in a box like this. 

 

mapread_zps14dfd2b8.png

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Mozilla really needed to focus on their core product for a while now. I will not mourn the death of pocket or AI garbage. One thing they don't do that I believe they should is advertise more, and not just to their core audience, especially their additional services. Let people know they actually exist.
    • Is this like tailscale?
    • I had no idea you could do this, thanks for the heads up!
    • Bonkers, really, when you think about the resources at Meta’s disposal.
    • You can now use Gemini in Google Forms to summarize responses by David Uzondu Over the last few months, Google has been aggressively pushing its Gemini AI into every corner of its Workspace apps, like generating entire documents from a prompt in Google Docs or creating fully editable charts in Sheets. Now, the company has set its sights on Google Forms. The latest update introduces a feature that uses Gemini to summarize text-based responses automatically. For any form with short-answer or paragraph questions, a new "Summarize responses" button will appear in the Responses tab once you collect more than three entries. Clicking it prompts Gemini to read the form's title, questions, and all the submitted text to spit out a summary of the key themes. Though Google bills this as a fresh expansion into Forms, we have actually had some Gemini intelligence in the app for a bit through the "Help me create a form" button. That feature, which drafts questions for you, was rolled out through the company's Workspace Labs program. For those unaware, Workspace Labs is basically Google's public testing ground, available in select countries, for new, and sometimes unproven, AI tools before a general release. Once a summary is generated, you can copy it to use elsewhere or hit "Retry" to see if Gemini comes up with a different take. If new responses roll in after you have generated a summary, you can click a "Refresh" button to update it with the latest data. For now, this feature is only available in English, and to use it, you'll need access to a paid Google Workspace plan, such as Business Standard, Business Plus, Enterprise Standard, or Enterprise Plus. It is also available to customers who pay for the Google AI Pro and Ultra plans or specific Gemini Education add-ons. The feature has started rolling out gradually, for Rapid Release domains, and will begin rolling out for Scheduled Release domains on June 26.
  • Recent Achievements

    • Week One Done
      Tech Dogs earned a badge
      Week One Done
    • Enthusiast
      computerdave91111 went up a rank
      Enthusiast
    • Week One Done
      Falisha Manpower earned a badge
      Week One Done
    • One Month Later
      elsa777 earned a badge
      One Month Later
    • Week One Done
      elsa777 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      529
    2. 2
      ATLien_0
      272
    3. 3
      +FloatingFatMan
      199
    4. 4
      +Edouard
      199
    5. 5
      snowy owl
      138
  • Tell a friend

    Love Neowin? Tell a friend!