Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had Inserted a image(India map)in to Picturebox,In that image the texts (City names)have to Selected(Change the Color) When Clicking on it.That i had done is, Inserted images(Round Shaped)near the cities to the pictureboxes and Typed the name of cities in labels,when i am clicked the Round Shape image then change the color of label(name of cities)but i had done is wrong(All in each click Events). i have to fire it in a single function and Call that picturebox id
Posted
Updated 12-Dec-11 4:20am
v3
Comments
Sergey Alexandrovich Kryukov 12-Dec-11 13:20pm    
Why using PictureBox at all? It does not look right for the purpose.
--SA

You don't.

Click (and all other) events are raised in response to something happening in the system - normally user input, timer or data related. You do not as a normal event raise system events in your code.

You can put the code for handling the event into a separate method, and then call that both from the Click event handler, and from your code to emulate the click.

What are you trying to achieve, that you think this would be a good idea? There may be a better way to handle it, if we knew what it was! :laugh:
 
Share this answer
 
To start with, you don't need PictureBox at all. This control is only good for something very simple and "almost" static. Many try to use if the something interactive or animated, which is possible, but then this control presents no benefits at all, only additional implementation hassles and waste of performance and resource.

You need to use just the Control, derive your class and override OnPaint where you render your picture directly. This way, you can combine your background map with some hot spot elements which you can make clickable.

For more detail, please see my past solution How do I clear a panel from old drawing[^].

Everything else depends on the graphical information you can obtain.

—SA
 
Share this answer
 
Put it on a single Function then call it on each of the buttons.

-Eduard
 
Share this answer
 
C#
protected void onClickHandler(object sender, EventArgs e)
       {

           string sample = ((PictureBox)sender).Name.ToString();

           if (((PictureBox)sender).BorderStyle == BorderStyle.None)
           {
               int ddd = Convert.ToInt32(sample.Length.ToString());
               string dd = sample.ToString().Substring(2, ddd - 2);
               string lbl = "lbl" + sample.Substring(2, ddd - 2);
               Control[] sam = this.Controls.Find(lbl, false);

            if (sam.Length != 0)
            {
                   Label lblsa = (Label)sam[0];
                   lblsa.ForeColor = Color.Red;

               }
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900