Solved

Easy c# question

Posted on 2003-11-13
7
333 Views
Last Modified: 2010-05-18
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
Comment
Question by:baal32
7 Comments
 
LVL 9

Accepted Solution

by:
tinchos earned 125 total points
ID: 9742142
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
 
LVL 10

Expert Comment

by:smegghead
ID: 9743901
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
 

Author Comment

by:baal32
ID: 9743925
I was so busy getting errors I didnt even notice the typo (borderStyle->BorderStyle).    :(

Thanks tinchos
0
Technology Partners: 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!

 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 12599747
Longshot:    Did you ever get this working?

I want to achieve a similar effect using a PictureBox in C#.
0
 

Author Comment

by:baal32
ID: 12607407
Yeah - as you can see it was just a matter of a typo.  I believe that you should have eq
0
 

Author Comment

by:baal32
ID: 12607416
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
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 12607445
 :)

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question