9 Replies - 9043 Views - Last Post: 07 April 2010 - 03:46 AM Rate Topic: -----

#1 Valeour  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 03-April 10

VB.Net Resource Manager.

Posted 03 April 2010 - 03:59 PM

Alright, here's an issue I have (Which I'm finding hard to search),

Basically, I have a bunch of images in a resource file, (All catagorized in folders if that's a problem)

And I want to load a resource by string. So...

Combobox1.text = "Default" // Let's just say i have a .png named Default.

PictureBox1.image = My.Resource.Combobox1.text //This is where I'm confused.(I'm aware it's not My.Resources.combobox1.text, it's just an example)


//In the actual way I'm doing it if it makes a difference:

Dim BackGround As Image = New Bitmap(My.Resources.???)


It's late, so I'm assuming I'm doing so stupid mistakes.

Please and Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: VB.Net Resource Manager.

#2 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 06:20 AM

So what is the actual problem? There is a good tutorial here that may help you.
Was This Post Helpful? 0
  • +
  • -

#3 Valeour  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 03-April 10

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 07:01 AM

Well, I have a bunch of pictures/images in a folder next to the .exe, and that was how i used to open them. (Application.startuppath & "image" etc),

Now this isn't exactly ideal, so i wanted to try and use a resource method, where the images will be embedded into the .exe.

So I'm just asking, how do i access the image files when they're in a resource folder, AND how do I access ones with a named defined via a combobox/textbox?

Like,

Textbox.text = "Default" 'The name of an image (Default.png) That's in the resource folder.

Dim BackGround As Image = New Bitmap() 'This is where I can't figure out what to insert.



I'm aware that it's usually like My.Resources.Default, but I need a way to Dim an image that's name is defined in a textbox.

I hope I cleared it up.


But I will look through that link now, thank you.
Was This Post Helpful? 0
  • +
  • -

#4 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 07:05 AM

for the image it should be something like Dim x as bitmap = my.resources.MyImage.Tobitmap
Was This Post Helpful? 0
  • +
  • -

#5 Valeour  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 03-April 10

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 07:09 AM

I'm aware of that, but I need the name from a textbox.

My.Resources.Textbox1.text.ToBitmap



Something like that. (But that does't work, I need a way that works.)
Was This Post Helpful? 0
  • +
  • -

#6 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 08:29 AM

Okay so what you are asking is how to get the name of an active resource from the string in a text box, so that it may be used in an application. Well what you are asking for is a conversion from string to type, and all things considered it may be easier to redesign your application slightly, you could of course use a giant if statement, but that is very costly on programming time. What I would recommend is doing something slightly more coy.

What I would do is follow this tutorial, to create a file that contains all the files and things you want.

you could use a 'hash table' so that you can easily search for the required object then use it in whatever way you desired, this allows more flexibility, and is good coding practice as you are not loading entire megabytes into memory.
Was This Post Helpful? 0
  • +
  • -

#7 Valeour  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 03-April 10

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 08:53 AM

I wanted to avoid giant if statements at all costs. xD

Anyway, I'll have a look at the link later. (Easter dinner and all that ;_; )

I've already rewritten my program twice, I hope it I don't have to do too much to it...

But again, thank you for your reply.

If I find my solution, I'll be sure to edit this post. (Unless someone has posted after me.)

Thanks again.



But while I'm still here, I might expand a bit.

I've got a Panel in which I paint various images on, (If you want to see the Application, i have various screenshots and the application is already online, but a slightly older version.)
When I paint, i basically dim through various parts of the picture I'm painting, the images that are loaded for the image currently come from a folder next to the .exe. All I want to do is, instead of loading images from a folder, I want to load them straight from the resource file that is supposedly embedded on the .exe. How i go about doing so, i have no clue.

This post has been edited by Valeour: 04 April 2010 - 09:01 AM

Was This Post Helpful? 0
  • +
  • -

#8 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 09:42 AM

yeah, you don't want a massive resource file. Also my method means they could be easily updated via the web, without needing a full application update.
Was This Post Helpful? 0
  • +
  • -

#9 Guest_Valeour*


Reputation:

Re: VB.Net Resource Manager.

Posted 04 April 2010 - 11:49 AM

View PostAsscotte, on 04 April 2010 - 08:42 AM, said:

yeah, you don't want a massive resource file. Also my method means they could be easily updated via the web, without needing a full application update.


Updated via the web!? That is perfect!

Mind you, won't that slow down the applicaton? i am constantly using the pictures.
Was This Post Helpful? 0

#10 Valeour  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 03-April 10

Re: VB.Net Resource Manager.

Posted 07 April 2010 - 03:46 AM

Okay, I fixed it.

Dim BackGround As Image = My.Resources.ResourceManager.GetObject(ComboBox1.text)


Guess I was just being blonde with the bitmap thing.

Thanks for all the help anyway guys.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1