English 中文(简体)
在C#中,我如何使顿语成为动态?
原标题:In C#, how do I make my button s text dynamic?

在编码C#时,我会说一个新东西,因此,我不会太过严。 我在《大本》前用行动编号,并指出它非常相似。

无论如何,在两种特性相互“金钱”的情况下,我基本上需要建立简单的应用。 特征名称应是动态的,各纽州应在名称之外发挥作用。

请帮助! 这是我迄今为止所做的:

namespace Lab_2
{
    public partial class Form1 : Form
    {
        Guy firstName;
        Guy secondName;
        int bank = 100;

        public Form1()
        {
            InitializeComponent();

            firstName = new Guy() { Cash = 100, Name = "Joe" };
            secondName = new Guy() { Cash = 50, Name = "Bob" };

            firstName = textBox1.Text;
            secondName = textBox2.Text;

            UpdateForm();
        }

        public void UpdateForm()
        {
            name1CashLabel.Text = firstName.Name + " has $" + firstName.Cash;
            name2CashLabel.Text = secondName.Name + " has $" + secondName.Cash;
            bankCashLabel.Text = "The bank has $" + bank;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Give $10 to " + firstName.Name;

            if (bank >= 10)
            {
                bank -= firstName.ReceiveCash(10);
                UpdateForm();
            }
            else
            {
                MessageBox.Show("The bank is out of money.");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bank += secondName.GiveCash(5);
            UpdateForm();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            secondName.ReceiveCash(firstName.GiveCash(10));
            UpdateForm();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            firstName.ReceiveCash(secondName.GiveCash(5));
            UpdateForm();
        }

        private void name1_Click(object sender, EventArgs e)
        {
            firstName.Name = textBox1.Text;
        }
    }
}
最佳回答

如果您的大麻只是在纽特州展示新的名称,那么你可以更新这些名称,如:

private void name1_Click(object sender, EventArgs e) 
{ 
    firstName.Name = textBox1.Text; 
    button1.Text = "Give $10 to " + firstName.Name;
}

www.un.org/Depts/DGACM/index_french.htm (如果有的话):

private void name2_Click(object sender, EventArgs e) 
{ 
    secondName.Name = textBox2.Text; 
    button2.Text = "Give $10 to " + secondName.Name;
}
问题回答

关键参数似乎是<代码> 姓名1_Click,该方法将第一个Name物体的名称更新到文本箱的内容中。 一旦你做过,你就希望恢复纽托邦的封顶。

一、导 言

public void RefreshButtonCaptions()
{
    button1.Text = "Give $10 to " + firstName.Name;
    button2.Text = "Give $10 to " + secondName.Name;
}

然后从上将其称作1_Click:

private void name1_Click(object sender, EventArgs e)
{
    firstName.Name = textBox1.Text;
    RefreshButtonCaptions()
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签