Passing Control name property

  • Thread starter Thread starter victor
  • Start date Start date
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
 
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)
 
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
 
Back
Top