• 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

    • It's an improvement overall but I'm also of the idea that they should just give users more options and let them have the menu they like instead of just going with one outline and some minor options (though finally getting rid of recommended is great). I know people who don't want pins and would rather it all be just the list/grid of apps. Others just want pins, others want them side by side and not up on top of each other. Have more layout options and let people mix and match, problem solved.
    • Hi all, I've got a Pioneer VSX 815-k receiver. Love this thing, however, my cat did his business on top of it and kinda recked it... Only analog works (5.1 surround RCA inputs). Normally I'd use toslink from mobo to digital in on the receiver, but the result is a ton of loud white noise over the music. Analog works just fine, so I'm forced to use the 3.5mm jacks on the rear of the mobo to the RCA inputs on the receiver. The issue I face is that there is no DTS or anything fun.. Originally, I could play all my MP3s or watch YouTube etc, and the subwoofer would be booming as I like because of the mixing from the DAC. Now with the analog, none of that is happening  I'm wondering if there's some kind of software solution for Windows to get the subwoofer to play as it did when I had it hooked up through toslink, but for analog out instead. As of now, only audio files that were encoded specifically to produce sound to the sub, will work, but nothing else. As to which onboard sound solution my mobo has, this from the website's description: 121dB SNR AMP-UP Audio with ALC1220 & High-End ESS SABRE 9018 DAC with WIMA audio capacitors Sound BlasterX 720°, the top-of-the-line audio engine solution for 4K gaming and entertainment  yea it uses that wonky SBx 720 app to change the audio effects n stuff.. but doesn't help with my issue Eventually yea, I wanna buy a new one. They're about $80 on ebay after shipping, but that will have to wait.
    • Serious question here. Why is the start menu such a heated topic? I can't remember the last time that I used the start menu for anything at all other than it pops up when I hit the WIN key on my keyboard before I type for the program I want to run and then hit Enter or to restart my machine. I honestly wish it would just go away, and it just be replaced with the PowerToys Run menu. Am I missing something with the Start menu? I see people always talking about installing third party replacements and such, but I just wonder what some are actually using the Start menu for that I might be missing out on. Genuine question. Hopefully not offending anyone as I know everyone has their own way to work and access things in the OS.
    • These are the Apple Watch models that support watchOS 26 by Aditya Tiwari Apple has announced the latest operating system upgrade for its smartwatch lineup, called watchOS 26, not watchOS 12, as many expected a while ago. The Cupertino giant has unified the software experience across its platforms by introducing the "Liquid Glass" software design and renaming all the operating systems to version 26. That said, the next question is which Apple Watch models will support watchOS 26. Apple has shared the official list of devices: Apple Watch Ultra 2 Apple Watch Ultra Apple Watch Series 10 Apple Watch Series 9 Apple Watch Series 8 Apple Watch Series 7 Apple Watch Series 6 Apple Watch SE (2nd Generation) The upcoming Apple Watch update brings several new features to your wrist. Liquid Glass design gives a fresh look to the UI with updated Control Center and translucent buttons within apps. It's new Workout Buddy feature can use an Apple Intelligence-enabled iPhone nearby to provide personalized, spoken motivation during workouts. Building on the Double Tap feature, you can now flick your wrist to perform actions like muting incoming calls, silencing timers, and dismissing notifications when your hands are full. It is available on Apple Watch Ultra 2 and Apple Watch Series 9 (or later). watchOS 26 is currently available for testing through the Apple Developer Program. It will roll out to general users during the fall season, when Apple is expected to refresh the Ultra and SE models. Note that your Apple Watch must be paired with an iPhone 11 (or later) or iPhone SE (2nd generation or later) running iOS 26. While the list of Apple Watch models that support watchOS 26 remains the same, it won't work with iPhone Xs/Xs Max and iPhone Xr, which were previously supported on watchOS 11. You can check out the respective lists of supported devices for iOS 26, iPadOS 26, and macOS 26 Tahoe.
  • Recent Achievements

    • Explorer
      MusicLover2112 went up a rank
      Explorer
    • Dedicated
      MadMung0 earned a badge
      Dedicated
    • Rookie
      CHUNWEI went up a rank
      Rookie
    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
  • Popular Contributors

    1. 1
      +primortal
      501
    2. 2
      ATLien_0
      268
    3. 3
      +FloatingFatMan
      257
    4. 4
      Edouard
      201
    5. 5
      snowy owl
      170
  • Tell a friend

    Love Neowin? Tell a friend!