Passing Control name property

V

victor

Hello guys,

I'm stuck at the following situation, please advise.

In my app there exists several control buttons (radio and push).
One of the methods is the following:

private void ManageControl (string ButtonName)
{
switch (ButtonName)
{
case "Button1"
{
Button1.BackColor=Color.FromArgb(nred,ngreen,nblue);
....
}
case "Button2"
{
Button2.BackColor=Color.FromArgb(nred,ngreen,nblue);
....
}
....
}

The case content is all the same except for the part of the Control
object (Button1, Button2, ...etc.); therefore I want to shrink it to
just one case parameterized with the appropriate button control name
which needs to be managed.
How do I pass these Control Name :) Button1, Button2 etc.) property to
the 'ManageControl' method?
Add parameter out/ref/object/.... ?

Thanks for your time!
greetz, victor
 
D

Daniel

Hi

Why not do something like this (i am guessing at your requirements here):

private void ManageControl ( Control c)
{
c.BackColor = Color.FromArgb(nred,ngreen,nblue);
}


Now any control you pass in will have its colour changed., (you may have to
cast to a button type)
 
V

victor

Daniel,
You're absolutely right!
I was somehow having a blackout and seeking a too difficult solution.
I'll rearrange my code and use your advise.
THANKS A LOT!
;-) victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top