[英]c# control dynamically created panel by dynamically created button
i've added a button that creates dynamically another buttons(lets call it accountButton) that accountButtons can adds dynamically panel and another button(exitButton) into panel我添加了一个按钮,它可以动态创建另一个按钮(我们称之为 accountButton),accountButtons 可以动态地将面板和另一个按钮(exitButton)添加到面板中
i cannot make dynamically created panel turn visible or invisible via accountButton我无法通过 accountButton 使动态创建的面板变为可见或不可见
private void account_save_Click(object sender, EventArgs e)
{
for (int i = 0; i < 1; i++)
{
BunifuFlatButton accountButton = addButton(i); // Hesap Butonu
Panel accountPanel = addPanel(i); // Hesap Paneli
BunifuImageButton exitButton = addexitButton(i); // Hesap Exit Butonu
panel_accounts.Controls.Add(accountButton); // MainPanel'e eklenen Hesap butonu
accountButton.Click += new EventHandler(this.accountButtonClick); // MainPanel'e eklenen Hesap butonu islevi
this.Controls.Add(accountPanel); // Main'e eklenen Hesap paneli
accountPanel.Controls.Add(exitButton); // Hesap paneli'ne eklenen Exit butonu
exitButton.Click += new EventHandler(this.exitButtonClick); // Hesap paneli'ne eklenen Exit butonu islevi
}
}
private void accountButtonClick(object sender, EventArgs e)
{
BunifuFlatButton currentaccountButton = (BunifuFlatButton)sender;
Panel currentPanel = (Panel)sender;
currentPanel.Visible = true;
}
This line will not work:此行将不起作用:
Panel currentPanel = (Panel)sender;
because the sender is the button that is clicked, not the panel.因为发件人是被点击的按钮,而不是面板。 Just a line above, you cast the exact same sender as a button.
就在上面的一行中,您投射了与按钮完全相同的发件人。
If the button is inside the panel, you can do this:如果按钮在面板内,您可以这样做:
Panel currentPanel = (Panel)currentaccountButton.NamingContainer;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.