Joseph Deakin
Joseph Deakin

Reputation: 11

How do I get the answer from a VisualBasic Input Box in C#

I have tried to make an InputBox in C#, I have managed to figure out how do this however, now I cannot extract an answer. Whenever I try to extract an answer it keeps coming up with the following error: "Cannot implicitly convert type 'string' to System.Windows.Forms.Label'." The code I have written so far is below.

private void devBtn1_Click(object sender, EventArgs e)
{
    string bluePlyr1;
    bluePlyr1 = Microsoft.VisualBasic.Interaction.InputBox("Name of Player 1");
    devLbl1 = bluePlyr1;
}

Thanks in advance.

Upvotes: 0

Views: 77

Answers (2)

Craig W.
Craig W.

Reputation: 18165

C#, unlike Visual Basic, does not have "default" properties. While your assignment of devLbl1 = bluePlyr1 would work in VB (because Text is the default property of a label) it won't work in C#. You need to specify the property you're trying to set.

devlbl1.Text = bluePlyr1;

Upvotes: 1

Bob
Bob

Reputation: 555

Then I'm pretty sure that devLbl1 is a Label

do

devLbl1.Text = bluePlyr1;

Upvotes: 5

Related Questions