Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Easy c# question

Posted on 2003-11-13
7
Medium Priority
?
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Accepted Solution

by:
tinchos earned 500 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 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