0

detect a click on another userControl than the current one

I have created a session selector for a project. The sessions are represented by userControl and its dynamically positioned in a panel I would like that when I press a UserControl of a session, this one changes it backColor into a color and that when another userControl than this one is selected that the color is removed on the current userControl and put on the new one I don't know if it's very clear, but here's what I tried to do: private void UserControl_Seance_Click(object sender, EventArgs e) { isClicked = true; this.BackColor = Color.Blue; } But the code stops there because I have no idea how to detect a click on another UserControl than this one Does anyone have a solution to detect a click on another userControl than the current one? Thank you.

25th Nov 2019, 10:03 PM
Rayane Staszewski
Rayane Staszewski - avatar
4 Antworten
+ 4
Your click event handler function sticks to the "another" element which is actually being clicked. in that function, access "this" element by its name, then you can change the background of "this" element. https://code.sololearn.com/WxJS5l68HHng/?ref=app
26th Nov 2019, 11:24 AM
Gordon
Gordon - avatar
+ 3
er... the demo is JavaScript, so of course you cannot copy directly. When you code C# GUI code, what tool are you using? Visual Studio?
27th Nov 2019, 4:38 AM
Gordon
Gordon - avatar
+ 1
I will try this in C # thanks to the handler I'll let you know thank you for your answer
26th Nov 2019, 4:44 PM
Rayane Staszewski
Rayane Staszewski - avatar
0
I have a little study your code is impossible it works because I do not know how much Userctrol there will be basic, and it is not very very recommended to copy paste code like that (for c#)
26th Nov 2019, 4:47 PM
Rayane Staszewski
Rayane Staszewski - avatar