• 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

    • Last chance: Solutions Architect's Handbook, Third Edition (worth $42.99) download by Steven Parker Claim your complimentary eBook worth $42.99 for free, before the offer ends today, June 10. Build a strong foundation in solution architecture and excel in your career with the Solutions Architect’s Handbook. Authored by seasoned AWS technology leaders Saurabh Shrivastav and Neelanjali Srivastav, this book goes beyond traditional certification guides, offering in-depth insights and advanced techniques to meet the specific needs and challenges of solutions architects today. This edition introduces exciting new features that keep you at the forefront of this evolving field. From large language models and generative AI to deep learning innovations, these cutting-edge advancements are shaping the future of technology. Key topics such as cloud-native architecture, data engineering architecture, cloud optimization, mainframe modernization, and building cost-efficient, secure architectures remain essential today. This book covers both emerging and foundational technologies, guiding you through solution architecture design with key principles and providing the knowledge you need to succeed as a Solutions Architect. It also sharpens your soft skills, providing career-accelerating techniques to stay ahead. By the end of this book, you will be able to harness cutting-edge technologies, apply practical insights from real-world scenarios, and enhance your solution architecture skills with the Solutions Architect's Handbook. This free offer expires today, June 10. How to get it Please ensure you read the terms and conditions to claim this offer. Complete and verifiable information is required in order to receive this free offer. If you have previously made use of these free offers, you will not need to re-register. While supplies last! Download Solutions Architect's Handbook, Third Edition (worth $42.99) for free Offered by Packt, view other free resources The below offers are also available for free in exchange for your (work) email: Solutions Architect's Handbook, Third Edition ($42.99 Value) FREE – Expires 6/10 AI and Innovation ($21 Value) FREE – Expires 6/11 Unruly: Fighting Back when Politics, AI, and Law Upend [...] ($18 Value) FREE - Expires 6/17 SQL Essentials For Dummies ($10 Value) FREE – Expires 6/17 Continuous Testing, Quality, Security, and Feedback ($27.99 Value) FREE – Expires 6/18 VideoProc Converter AI v7.5 for FREE (worth $78.90) – Expires 6/18 Macxvideo AI ($39.95 Value) Free for a Limited Time – Expires 6/22 The Ultimate Linux Newbie Guide – Featured Free content Python Notes for Professionals – Featured Free content Learn Linux in 5 Days – Featured Free content Quick Reference Guide for Cybersecurity – Featured Free content We post these because we earn commission on each lead so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin The above deal not doing it for you, but still want to help? Check out the links below. Check out our partner software in the Neowin Store Buy a T-shirt at Neowin's Threadsquad Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: An account at Neowin Deals is required to participate in any deals powered by our affiliate, StackCommerce. For a full description of StackCommerce's privacy guidelines, go here. Neowin benefits from shared revenue of each sale made through the branded deals site.
    • Yes. And if anyone has problems, it's because "Windows 11 is buggy..."
    • https://lunduke.locals.com/post/4387539/firefox-money-investigating-the-bizarre-finances-of-mozilla
  • Recent Achievements

    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
    • Collaborator
      Carltonbar earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      498
    2. 2
      ATLien_0
      268
    3. 3
      +FloatingFatMan
      229
    4. 4
      +Edouard
      199
    5. 5
      snowy owl
      151
  • Tell a friend

    Love Neowin? Tell a friend!