+ Reply to Thread
Results 1 to 7 of 7

Thread: Using Recources in VB.NET

  1. #1
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Using Recources in VB.NET

    You can store Strings, Images, Icons, Audio, Files etc. as resources in VB.NET, if you can do you can then access them by your code, this is a good way if you want to include images etc. in your program without have to make sure the files exists at the right path on the users computer. To go to the resources window right click on "My Project" in the solution explorer and then click "Open":


    Using Recources in VB.NET-recources1.png




    Now click on Resources in the list to the left:


    Using Recources in VB.NET-recources2.png


    If you have made it right you should now see something like this:
    Using Recources in VB.NET-recources3.png



    Adding Resources

    The easiest way to add a resource is to do import it from a file, to do this click at "Add Resource" and then "Add Existing File...". Now select your file(s) and it will be added, observe that the resources will be sorted by type so if you don't find the one you added you have to change the type in the top left corner. After adding some resources it could look like this:


    Using Recources in VB.NET-recources4.png






    Using Resources


    To access the resources you write My.Resources.[the resource's name], like this:

    [highlight=VB.NET] My.Resources.test1[/highlight]

    So this will give us the Resource called test1. To use it we can do something like this:


    [highlight=VB.NET] Me.BackgroundImage = My.Resources.test1[/highlight]

    but if we only do this it doesn't seem so useful since we could just have added the image to be the background of the form in the design view, but if we want to have different backgrounds, like this:



    [highlight=VB.NET] Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Select Case Now.Minute
    Case Is < 15
    Me.BackgroundImage = My.Resources.test1
    Case Is < 30
    Me.BackgroundImage = My.Resources.test2
    Case Is < 45
    Me.BackgroundImage = My.Resources.test3
    Case Is < 60
    Me.BackgroundImage = My.Resources.test4
    End Select
    End Sub[/highlight]

    You've probably already got the idea. If you want to get one of the resources you've already added to be able to modify it or something similar you can find it in your project folder in the sub folder called resources.


    That was everything about resources in VB.NET, hope you've learned something and understood why it's good to use them.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Using Recources in VB.NET

    Nicely done. +rep

  4. #3
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Using Recources in VB.NET

    Nice +rep
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    arkanion is offline Newbie
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Re: Using Recources in VB.NET

    thanks man

  6. #5
    Join Date
    Sep 2010
    Location
    Yangon, Myanmar
    Posts
    7
    Rep Power
    0

    Re: Using Recources in VB.NET

    thanks

  7. #6
    HappyTear is offline Newbie
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Re: Using Recources in VB.NET

    thanks ! but
    what if i want to launch/run file from my resurces ?
    what should i do ?

  8. #7
    Floating is offline Newbie
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Re: Using Recources in VB.NET

    Very nice one... I think this is a great idea; placing resources in the app. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts