Braheen
Braheen

Reputation: 29

Lable control in argument

I am trying to send massage and changing the color of Labels.

private void updateStatus(string massageText, Label label)
{
    txtStatus.Text = massageText;
    label.BackColor = Color.Red;
 }

when i try to apply this;

updateStatus("Level-1 Complete", Label1);
updateStatus("Level-2 Complete", Label2);

it give error of

The best overloaded method match for 'Taal.Form1.updateStatus(string, System.Windows.Forms.Label)' has some invalid arguments D:\Taal\Taal\Form1.cs"

What is wrong in this code?

Upvotes: 0

Views: 92

Answers (2)

Braheen
Braheen

Reputation: 29

Actually my label was on Status Bar So with the help from comments i have correct it. Thanks

private void updateStatus(string massageText,ToolStripLabel label)
        {
            txtStatus.Text = massageText;
            label.BackColor = Color.Red;


        }

Upvotes: 0

Damith
Damith

Reputation: 63105

try with, below method can be reused for any form control

private void updateStatus(string massageText, System.Windows.Forms.Control control)
{
    txtStatus.Text = massageText;
    control.BackColor = Color.Red;
 }

Upvotes: 1

Related Questions