Hi am quite new to visual studios.

This is my code so far to make an example of an atm, where you the put the amount in and then click credit it adds to the balance and click debit and it takes it out. am doing this inc# wpf application.

so far i have this.

public MainWindow()
        {
            InitializeComponent();
        }

    private double totalamount = 0;
    public string balance1;


    private void buttoncredit_Click(object sender, RoutedEventArgs e)
    {
        totalamount = totalamount + double.Parse(textboxamount.Text);

        balance1 = "Your Balance is: £";

        label2 = balance1 + totalamount;

and then this error comes along . "Cannot implicitly convert type 'string' to 'System.Windows.Controls.Label"

I have done this in forms . where i say label2.text = ..... and it works . but on the wpf i can't do this. if someone can guide me it will be much appricated.

thanks .

有帮助吗?

解决方案

For wpf the equivalent is:

label2.Content = balance1 + totalamount;

其他提示

You want to set the Text property of the Label not the Label itself. So try this:

In Windows form:

label2.Text = balance1 + totalamount;

In WPF:

label2.Content = balance1 + totalamount;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top