【问题标题】:Textbox into Label [closed]文本框到标签[关闭]
【发布时间】:2016-11-09 06:19:33
【问题描述】:

我正在尝试制作一个程序,每当您在文本框中键入一个字母时,字母中的字母编号就会出现在标签中......我尝试了一些这样的代码:

private void textBox1_TextChanged(object sender, EventArgs e)
{   
    string userInput = textBox1.Text;            //get string from textbox
    if(string.IsNullOrEmpty(userInput)) return;  //return if string is empty
    char c = char.ToUpper(userInput[userInput.Length - 1]); //get last char of string and normalize it to big letter
    int alPos = c-'A'+1;                         //subtract from char first alphabet letter

    label1 = alPos.ToString();    
}

我想要一个这样的程序

【问题讨论】:

  • 那么问题出在哪里?
  • 您的问题应该更具体、更明确
  • 您的代码似乎可以运行,请问有什么问题?
  • 我不知道如何运行该代码。

标签: c# winforms


【解决方案1】:

这里label1 是您放置在 UI 中的标签,并且您正试图为该控件分配一个字符串值。此类转让无效且不允许。您的要求是将alPos 分配为标签控件的文本属性。所以你的查询应该是这样的:

label1.Text = alPos.ToString();    

【讨论】:

  • 天哪,谢谢!我不知道我该如何感谢你:(!我真的很感激
猜你喜欢
  • 1970-01-01
  • 2012-11-03
  • 1970-01-01
  • 2019-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多