Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Easy c# question

1) I have several pictureboxes wired to the same event handler (dimThis(object o, EventArgs e)).  I want to modify an attribute of whicever picturebox fired the event.  How is this done?

code:
.
.
.
this.pictureBox1.Click += new System.EventHandler(dimThis);
this.pictureBox2.Click += new System.EventHandler(dimThis);
.
.
private void dimThis(object sender, System.EventArgs e)
{
        ??? sender.borderstyle doesnt work, neither does
((System.Windows.Forms.PictureBox)(sender)).borderStyle

}
ultimately I'm just trying to set up rollover button styles as you might have guessed...


Also if you can provide me with some REALLY GOOD beginner tutorials I will add 50 points to the Q.  They can't just be the top google picks tho, I've already hit those.
0
baal32
Asked:
baal32
1 Solution
 
tinchosCommented:
Hi baal32

What you can do if the following..............

When you have the handler

private void dimThis(object sender, System.EventArgs e)
{
       ??? sender.borderstyle doesnt work, neither does
((System.Windows.Forms.PictureBox)(sender)).borderStyle

}

the sender parameter represents the control who fired the event being handled (in this case the picturebox that was clicked)................

so what you can do as you said.............

the problem I find with your code is that the property is "BorderStyle", not "borderStyle"

private void dimThis(object sender, System.EventArgs e)
{
    ((System.Windows.Forms.PictureBox)(sender)).BorderStyle = ......;
}

I don't have an appropiate code so as to test it, but I'm quite sure it must work this way

If not, please describe why you say it's not working....... (not compiling, an exception is thrown, etc)

Hope this helps

Tincho
0
 
smeggheadCommented:
if you are using visual studio, intellisense should come up with BorderStyle as a property. If not, something is wrong.

What is your error ?

Smg.
0
 
baal32Author Commented:
I was so busy getting errors I didnt even notice the typo (borderStyle->BorderStyle).    :(

Thanks tinchos
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Tom KnowltonWeb developerCommented:
Longshot:    Did you ever get this working?

I want to achieve a similar effect using a PictureBox in C#.
0
 
baal32Author Commented:
Yeah - as you can see it was just a matter of a typo.  I believe that you should have eq
0
 
baal32Author Commented:
ual access to the properties of any control by casting the sender as that type of control.  And I say this with the full confidence of a total C# newbie.
0
 
Tom KnowltonWeb developerCommented:
 :)

My current solution is leaving behind  the BorderStyle  (it is not resetting it to BorderStyle.None when I leave the picturebox).

Can you help?

If so......here is my question:  

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21209321.html

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now