Solved

Easy c# question

Posted on 2003-11-13
7
300 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by: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: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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now