简体   繁体   中英

button change text c#

im trying to make a button change a label. I was able to do it before but i cant anymore.

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

    private void button1_Click(object sender, EventArgs e)
    {
        if (button1.Click)
            label1.Text == ("Lawl");
    }
}

It comes up with 2 errors:

在此处输入图片说明

button1.Click is an event, not a property. Assuming you've set button1_Click() as an event handler for Click using the Designer, you can simply remove that if altogether and write:

label1.Text = "Lawl";

Note also the single = since you want assignment, not comparison.

=

Is the assign operator.

==

Is the equality operator.

label1.Text == ("Lawl");

Is interpreted as label1's text equal to "Lawl"

You should write instead:

label1.Text = "Lawl";

Which is read as: assign "lawl" to label1's text property.

Edit (didn't even see the if...):

Also button1.click is an event, not a property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM