Romo Daneghyan
Romo Daneghyan

Reputation: 2189

Duplication Controls Winforms

I have such a situation here. Let's say we have three button on our Form, and one Control, which is Panel, and which is hidden when the Form is loaded. Here is it enter image description here

When I click on Button 1, that Panel have to be shown under Button1, when clicking on Button2, it have to be showned under Button2 and so on. Let's say I clicked on Button2.

enter image description here

Now I want that same Panel to show, when Clicking on Button1 and not at the same place. I need the same panel to be showed under buttons when clicking them.For example, the same panel is showing when clicking button 3 enter image description here I made this only working for only one button. I can't have 2 controls with same attributes, but I need somehow to duplicate that control.I And I think it have to be done with UserControl.

Upvotes: 2

Views: 79

Answers (1)

user3177651
user3177651

Reputation:

private void btn_click(Control sender, EventArgs e)
{
    var btn = sender as Button;
    panel1.Left = btn.Left;
}

now assign this even handler to click event for all buttons.

The var btn.... line will represent the button that was clicked, or the control that triggered the event, so from there you can set the panel's location.

Upvotes: 2

Related Questions