Solved

Easy c# question

Posted on 2003-11-13
7
318 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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