+ Reply to Thread
Results 1 to 4 of 4

Thread: Using Recources in VB.NET

  1. #1
    Moderator Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe's Avatar
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Age
    16
    Posts
    8,818
    Blog Entries
    5

    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. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Using Recources in VB.NET

    Nicely done. +rep

  3. #3
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,698
    Blog Entries
    57

    Re: Using Recources in VB.NET

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

  4. #4
    Newbie arkanion is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    10

    Re: Using Recources in VB.NET

    thanks man

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Replies: 8
    Last Post: 01-19-2010, 08:33 PM
  2. Replies: 3
    Last Post: 11-02-2009, 07:40 PM
  3. Replies: 3
    Last Post: 11-02-2009, 07:18 PM
  4. Replies: 1
    Last Post: 11-02-2009, 07:43 AM
  5. Need a program created in VB.Net
    By Thomas in forum MarketPlace
    Replies: 0
    Last Post: 08-29-2007, 06:02 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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