delete
delete

Reputation:

How to visually let the user know that something is selected?

For example, I have a userControl that I want a user to be able to "Select".

Here is the code I'm using:

private void ptbImage_Click(object sender, EventArgs e)
{
    SelectControl();
}

private void SelectControl()
{
    this.BackColor = Color.FromArgb(235, 243, 253);
}

If I have many controls inside of this user control things get messy soon! :P Is there a to globally wrap around every control? Like a Click event for everything inside the control. If there isn't I'll just manually create a click even for every control to globally capture input. Thanks!

alt text

Upvotes: 1

Views: 83

Answers (3)

Pedery
Pedery

Reputation: 3636

foreach (Control ctrl in yourContainerControl.Controls)  {
    ctrl.Click += new System.EventHandler(ctrl_Click);   
}

You can also capture events application-wide, and handle them before they are directed to the control itself.

Upvotes: 0

Contra
Contra

Reputation: 1711

In the form's InitializeComponent method you could run a foreach through every control on the form and set the Click eventhandler to ptbImage_Click

Upvotes: 0

joaocarlospf
joaocarlospf

Reputation: 1157

Yes...

You can link the event of each control to the same event method, like this:

ptbImage1.Click += new System.EventHandler(ptbImage_Click);
ptbImage2.Click += new System.EventHandler(ptbImage_Click);
ptbImage3.Click += new System.EventHandler(ptbImage_Click);

etc..

Upvotes: 1

Related Questions