【问题标题】:C# Forms Event, want button click to produce two buttonsC# Forms 事件,希望按钮单击产生两个按钮
【发布时间】:2021-11-04 20:52:13
【问题描述】:

我正在尝试获取它,因此当您单击按钮(即开始)时,它会为您带来两个按钮,noob 和 medium。我不知道如何让第二个出现。 ID 用于 button1,所以我尝试将第二个重命名为 button1,但不起作用。如何再次传递 button1 以使其从一个按钮逻辑生成两个按钮?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace App2341
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Noob";
            button1.Location = new Point(100, 100);
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            button1.Text = "Medium";
            button1.Location = new Point(100, 150);
        }
        private void Form1_Load(object sender, EventArgs e)
        {



        }
    }
}

【问题讨论】:

  • "Spawn" 不是计算机科学或编程术语。你到底是什么意思?
  • 上下文中的措辞好吗?我希望按钮在单击时从一个按钮产生两个按钮,目前只有一个
  • 目前您没有创建任何按钮,而是修改现有的button1。您可以事先创建两个新按钮,然后根据需要使它们可见。或者您使用 new Button() 动态创建它们。
  • 如何使它们不可见,然后在点击时可见?

标签: c#


【解决方案1】:

尝试在设计器中创建三个按钮并为每个按钮命名,然后将开始按钮的可见性设置为可见,将其他两个按钮的可见性设置为隐藏。当您单击开始按钮时,您将开始按钮的可见性设置为隐藏,并将其他两个按钮的可见性设置为可见。

设置按钮可见性:

button1.Visible = true; //to show the button
button1.Visible = false; //to hide the button

【讨论】:

  • 非常感谢!感谢帮助!最佳社区
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-20
  • 1970-01-01
相关资源
最近更新 更多