473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Change picture on click, back and forth?

1
Hi!
Tried searching the forums but I came up short, sorry if I'm asking the same stupid question over and over.
I got a code snippet that looks like this:

Expand|Select|Wrap|Line Numbers
  1. private void pictureBox1_Click(object sender, EventArgs e)
  2. {
  3.       pictureBox1.Image = Image.FromFile(@"IMAGEPATH\test1.jpg");
  4. }
Since I'm a real newbie at programming I want to know how to code to make the other picture clickable aswell and when you click it it returns to the first image in the picturebox which you can click and so forth. Should I make states for the different images or how should I go about doing it?. Any help or links are appreciated!
Apr 22 '10 #1
3 8557
Christian Binder
218 Expert 100+
@kekela
You could use a boolean which you toggle in the pictureBox1_Click()-method and depending on it's state (true/false) you show the first or the second image.

The pictureBox1_Click()-method will also be called when you display another image in pictureBox1 because this doesn't mean you've clicked a dedicated picture but the control which can contain any picture.
Apr 22 '10 #2
Frinavale
9,735 Expert Mod 8TB
I'm not sure what you mean by "other picture" when in the following statement:
I want to know how to code to make the other picture clickable aswell and when you click it it returns to the first image in the picturebox which you can click and so forth.
In the code snippet you have posted you only have 1 picture box.
I don't see any "other" picture.

Also what do you mean by "returns the first image"?
Return it where?

What is your application supposed to do?

-Frinny
Apr 22 '10 #3
tlhintoq
3,525 Expert 2GB
A) Pictures are not clickable. The PictureBox control is clickable. So you can't make the other picture clickable. You will have to write some logic that checks which picture is currently being shown, and swap when the PictureBox control is clicked.

B) This is going to get you in trouble:
Expand|Select|Wrap|Line Numbers
  1. pictureBox1.Image = Image.FromFile(@"IMAGEPATH\test1.jpg");
If you keep loading from harddrive every time you click you are duplicating a lot of work. Why load the same thing over and over? Load your two images into variables one time at the start, then just swap.

Expand|Select|Wrap|Line Numbers
  1. PictureAlpha = Image.FromFile(path1);
  2. PictureBravo = Image.FromFile(path2);
  3. // Your click logic
  4. PictureBox1.Image = PictureAlpha;
Apr 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jeff | last post by:
Hiya, Im currently in the process of developing a picture browser, I want it to run off a CD, basically I have 2 questions for the group. The first is how do I get the program to only view the...
1
by: Major Man | last post by:
Hi, I have this .jpg picture, it's about 700x200 (it's wide, but narrow across top to bottom). What I wanna do is display it on a 300x200 window, and have it pan across back and forth. I've...
2
by: Raigo | last post by:
There is a bug with IE6 handling Javascript onMouseOver and onMouseOut events. Can it be replaced somehow with CSS? For example when I want to change images when user moves mouse to certain HTML...
2
by: Nick Calladine | last post by:
Is this possible to ... I wish to get the value of a dropdown select but gets is indexable value (dont know if that is the right term) if that is possible (the position it assigned get assigned...
6
by: Salad | last post by:
Hi: I have a Bill of Lading template from the printer that I saved as a BMP. I created a new report and in the report's picture property told it the BMP file name. It brought the image in just...
5
by: Charles F McDevitt | last post by:
I'm converting some old programs that use old iostreams. In one program, the program is using cout to output to the stdout stream. Part way through, the program wants to put some binary data out,...
4
by: Elton | last post by:
Dear All, I am new to vb , please help. I have a picture , and a picture_click( ) function. What I want to do is to have a simulate a click event onto the picture in a loop. However, when I...
4
by: =?Utf-8?B?Q2FybGFKYWRl?= | last post by:
Can anyone help me? I need to use picture it 2000 every day and use to use it on Windows XP and had NO problems at all. If I would open up windows explorer i could be in my folder that has all of...
17
by: merrily | last post by:
Read in one forum the question someone asked after successfully (sort of) installing Picture It 2000 on new computer with Vista. Will this person or any other help me accomplish this install on...
18
by: wizdom | last post by:
Help - change text on click - text has another onclick inside with php variables ---------- I think what I'm trying to do is simple. I have a 2 buttons on a page. 1 button allows a thread of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.