School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
You're Browsing As A Guest! Register Now...
Become an Expert!

Join 358,489 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,219 people online right now.Registration is fast and FREE... Join Now!



Asking on how to change one picturebox image into a different image wh

52 Weeks of Code Challenge: Android

Week #11 of the 52 Weeks of Code Challenge is Android, you should give it a shot. Click Here!

Asking on how to change one picturebox image into a different image wh Rate Topic: -----

#1 le052383  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-November 09


Dream Kudos: 0

Posted 20 November 2009 - 06:11 AM

Hi,

I am doing a battleship project in a C ++/C sharp course and is wondering how one can change the image of a title when hover or clicked on. To explain further, below is a mock up image of what I want to achieve:

Posted Image

The titles used above are pictureboxes and unless there is a easier way, I am thinking of using a different title pic [darker blue] when highlighted. I am thinking it would be something like


private void Tile1A_Click(object sender, EventArgs e)
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
	public partial class Form2 : Form
	{
		public Form2()
		{
			InitializeComponent();
		}

		private void Tile1A_Click(object sender, EventArgs e)
		{
		WindowsFormsApplication2.Resource1.tilehl = WindowsFormsApplication2.Resource1.tile;
		}



However, when I try the line above, visual basic mentions something like "WindowsFormsApplication2.Resource1.tilehl' cannot be assigned to -- it is read only"

Are there a way to alter one image in a picturebox to another? Thanks

Mod Edit:
When posting code please use code tags like below.
:code:
Was This Post Helpful? 0
  • +
  • -


#2 SixOfEleven  Icon User is online

  • 1-888-611-RULZ
  • Icon

Reputation: 272
  • View blog
  • Posts: 4,374
  • Joined: 18-October 08


Dream Kudos: 1100

Expert In: C, C#, XNA, Game Programming, Chocolate

Re: Asking on how to change one picturebox image into a different image wh

Posted 20 November 2009 - 06:26 AM

What you would want to do is hook into the MouseEnter and MouseLeave events of the picture box. In the MouseEnter event you would just set the Image property of the picture box to be the image you want displayed. On the MouseLeave event you would switch back to the old image.
Was This Post Helpful? 0
  • +
  • -

#3 le052383  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-November 09


Dream Kudos: 0

Re: Asking on how to change one picturebox image into a different image wh

Posted 20 November 2009 - 07:02 AM

View PostSixOfEleven, on 20 Nov, 2009 - 06:26 AM, said:

What you would want to do is hook into the MouseEnter and MouseLeave events of the picture box. In the MouseEnter event you would just set the Image property of the picture box to be the image you want displayed. On the MouseLeave event you would switch back to the old image.


Thanks. You suggestion helps whereas it is what I want to do (I tested it using textboxes) but the code I use still doesn't work.

What I mean is that I tried the codes below to try to change the image in the picturebox:

WindowsFormsApplication2.Resource1.tile = WindowsFormsApplication2.Resource1.tilehl;


and

picbox1A = WindowsFormsApplication2.Resource1.tileh;



WindowsFormsApplication2.Resource1.tile is the actual image whereas picbox1A is the picturebox. When I add color=#33CCFF]WindowsFormsApplication2.Resource1.tile = WindowsFormsApplication2.Resource1.tilehl;[/color]
in my source, I would get an error saying "WindowsFormsApplication2.Resource1.tile cannot be assigned to" and if I tried 2nd line, it says that I can't simply convert System.Drawing.Bitmap to System.Windows.Forms.PictureBox
Mod Edit:
Please, when you are posting code use code tags, not color tags.

This post has been edited by le052383: 20 November 2009 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

#4 SixOfEleven  Icon User is online

  • 1-888-611-RULZ
  • Icon

Reputation: 272
  • View blog
  • Posts: 4,374
  • Joined: 18-October 08


Dream Kudos: 1100

Expert In: C, C#, XNA, Game Programming, Chocolate

Re: Asking on how to change one picturebox image into a different image wh

Posted 20 November 2009 - 07:09 AM

For setting the image of the picture box what you would do is cast the bitmap in the resource to an Image.

picturebox1A.Image = (Image)WindowsFormsApplication2.Resource1.tileh;


Was This Post Helpful? 0
  • +
  • -

#5 le052383  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-November 09


Dream Kudos: 0

Re: Asking on how to change one picturebox image into a different image wh

Posted 20 November 2009 - 07:14 AM

View PostSixOfEleven, on 20 Nov, 2009 - 07:09 AM, said:

For setting the image of the picture box what you would do is cast the bitmap in the resource to an Image.

picturebox1A.Image = (Image)WindowsFormsApplication2.Resource1.tileh;



It works. Thanks.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month