Get image from resources

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2004
Posts: 4,190
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 483
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Get image from resources

 
0
  #1
Mar 7th, 2008
When I created new project I went to Solution Explorer and in Properties I double clicked on Resources.resx. Here I clicked on Add Resource and Add Existing File. Selected images been added and I can use them for darg&drop on form.
My problem is I need to create sort of rollover effect on pictureBox. PictureBox image property is set to none for start. When I go with mouse over pictureBox I want to upload image from resources. How do I do it?

pictureBox.Image = ? ? ? ? ?

PS: Any good place with C# tutorials?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Get image from resources

 
0
  #2
Mar 7th, 2008
C# on MSDN: http://msdn2.microsoft.com/en-us/vcsharp/default.aspx

  1. pictureBox1.Image = Properties.Resources.[image name];
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,190
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 483
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Get image from resources

 
0
  #3
Mar 7th, 2008
OK no error after that, but once I get mouse over pictureBox image is not uploaded. Did I forgot somethink like Paint? I wish they library system was more like Java API...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Get image from resources

 
1
  #4
Mar 8th, 2008
In pictureBox event handler (MouseOver) assign the picturebox.image to the image which in resources. It works!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 5
Reputation: peterpollen is an unknown quantity at this point 
Solved Threads: 1
peterpollen peterpollen is offline Offline
Newbie Poster

Re: Get image from resources

 
0
  #5
Mar 9th, 2008
You have to be a little slow when moving your mouse over the picturebox. If you want precision movement try considering writing code in the MouseEnter, MouseLeave event handlers.

Thanks,
Peter Pollen <advertising url snipped>
Last edited by happygeek; Mar 9th, 2008 at 8:07 am. Reason: fake sig, please see the rules
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,190
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 483
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Get image from resources

 
0
  #6
Mar 10th, 2008
I forgot to attach silly event handler

For anybody who wish to generate 2D array of pictureBoxes on runtime here is code snipped for it
  1. for (int x = 0; x < stonePlaced.GetUpperBound(0); x++)
  2. {
  3. for (int y = 0; y < stonePlaced.GetUpperBound(1); y++)
  4. {
  5. stonePlaced[x, y] = new PictureBox();
  6. stonePlaced[x, y].Size = new Size(80, 80);
  7. stonePlaced[x, y].Location = new Point((80 * x),(80 * y));
  8. stonePlaced[x, y].BackColor =
  9. System.Drawing.Color.Transparent;
  10. stonePlaced[x, y].MouseHover +=
  11. new System.EventHandler(this.stonePlaced_MouseHover);
  12. stonePlaced[x, y].MouseLeave +=
  13. new System.EventHandler(this.stonePlaced_MouseLeave);
  14. boardPanel.Controls.Add(stonePlaced[x, y]);
  15. }
  16. }

And event listeners
  1. private void stonePlaced_MouseHover(object sender, EventArgs e)
  2. {
  3. PictureBox pb;
  4. pb = (PictureBox)sender;
  5. pb.Image = Properties.Resources.purple;
  6. }
  7.  
  8. private void stonePlaced_MouseLeave(object sender, EventArgs e)
  9. {
  10. PictureBox pb;
  11. pb = (PictureBox)sender;
  12. pb.Image = null;
  13. }
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC