c# - 如何在另一个按钮旁边生成一个按钮?
问题描述
我使用自定义按钮创建了单独的类,我希望在单击此“newButton”时弹出该类。我该如何手动完成?所以如果有多个“newButtons”并且我想隐藏以前的自定义按钮我的问题是我不知道如何寻找新按钮的位置,因为它位于自动放置它们的 flowLayout 中。
Button newButton = new Button();
newButton.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(175)))), ((int)(((byte)(241)))));
newButton.FlatAppearance.BorderSize = 2;
newButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
newButton.Font = new System.Drawing.Font("Arial", 10.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
newButton.ForeColor = System.Drawing.Color.White;
newButton.Location = new System.Drawing.Point(158, 288);
newButton.Size = new System.Drawing.Size(150, 38);
newButton.UseVisualStyleBackColor = true;
newButton.Text = k.grp;
newButton.Click += (sender, e) => newButton_Click(sender, e);
if (checkinNames.Contains(newButton.Text))
{ }
else
flowLayoutPanel5.Controls.Add(newButton);
checkinNames.Add(k.grp);
解决方案
您无法直接在 FlowLayoutPanel 中通过特定属性来实现它。放置在其中的所有可视控件都会根据 FlowLayoutPanel 的大小自动调整其位置。
这是通过设置按钮的解决方法border, backcolor, text and enable
。
private void HideButton(Button button)
{
button.BackColor = this.BackColor;
button.Text = string.Empty;
button.TabStop = false;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
button.Enabled = false;
}
希望这可以帮到你。
推荐阅读
- c# - 使用路由约束时,如果路由参数验证失败,为什么 API 返回 404 而不是 400
- node.js - 快递 | 节点.js | oauth2 未进行身份验证
- delphi - DELPHI 上 ZEOSDBO 组件的问题
- python - 了解递归算法及其工作原理
- python - matplotlib 的组标题
- docker - Docker swarm 失去了管理者?
- amazon-web-services - 尝试在后确认功能中使用模型
- r - 因子查找中 NA 的意外回报
- javascript - /v2/search/SARS_CoV_2/GID1716 处的 NoReverseMatch
- python-3.x - Python - 带参数的 pypsexec 命令