7 Replies - 467 Views - Last Post: 23 June 2017 - 11:07 AM

#1 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

How to Switch an Image in pictureBox?

Posted 23 June 2017 - 09:03 AM

Happy friday to all you working coderz,
Quick question from a n00blet:
anyone know how to switch the image in a pictureBox when you're using VC++/.NET?

There are a ton of answers on how to do it with C# but I tried doing syntax conversions and unlike some things, this one doesn't seem there's cross syntaxability (not a word, I know).

I tried:
pictureBox1->Image = Image->FromFile("C:/mypicture.jpg")



.. didn't work.

Also tried my usual: which is to just take the code that was generated by the forms designer and mod it. But that didn't work either:

pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox2.Image")));



compiler error:

"identifier 'resources' is undefined"

halp? :dots:

Is This A Good Question/Topic? 0
  • +

Replies To: How to Switch an Image in pictureBox?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,090
  • Joined: 12-June 08

Re: How to Switch an Image in pictureBox?

Posted 23 June 2017 - 09:14 AM

Didn't work as in nothing happened even if you minimized/restored the window, or didn't work as in threw an exception?
Was This Post Helpful? 0
  • +
  • -

#3 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: How to Switch an Image in pictureBox?

Posted 23 June 2017 - 09:33 AM

Exceptions for days... no compile.

I had a few techniques I tried yesterday night that just didn't change the image but I can't remember the lines for those.

both of those throw exceptions, though.

I'm guessing the second thing I tried didn't work because it's not in the right scope. But usually I can just take the designer code and change it then throw it inside a button EventArg. Not in this case.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,090
  • Joined: 12-June 08

Re: How to Switch an Image in pictureBox?

Posted 23 June 2017 - 09:36 AM

M'kay.. care to share the exceptions?

Also have you looked at the documentation? Say anything from Image::FromFile ?
https://msdn.microso...y/0t3sakh9.aspx

Don't forget \\ and not just \.
Was This Post Helpful? 1
  • +
  • -

#5 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: How to Switch an Image in pictureBox?

Posted 23 June 2017 - 09:58 AM

I did read that guide. I'll try it again and post the exceptions. Also, I DO remember the \\ !!! yes that was a very nice tip. Use it daily.
Was This Post Helpful? 0
  • +
  • -

#6 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: How to Switch an Image in pictureBox?

Posted 23 June 2017 - 10:37 AM

Modi, actually I didn't read that one.... it's different than the one I found. Ty
Was This Post Helpful? 0
  • +
  • -

#7 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: How to Switch an Image in pictureBox?

Posted 23 June 2017 - 11:03 AM

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		Image^ image = Image::FromFile("C:\\YOURFILEPATHHERE\\2.png");
		pictureBox1->Image = image;


	}




Modi!!! yourethemannowdog.com

THANKS!!!!!!!!!!!!!!!!!! :frenchy:
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13554
  • View blog
  • Posts: 54,090
  • Joined: 12-June 08

Re: How to Switch an Image in pictureBox?

Posted 23 June 2017 - 11:07 AM

Good ol' scope resolution operators.
https://en.wikipedia...perator#Example
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1