cannot convert type int to System.Windows.Forms.Label

前端 未结 3 1898
清歌不尽
清歌不尽 2021-01-29 11:56

I am making a random number generator but i cant get it to work. it says cannot convert type int to System.Windows.Forms.Label

    private void button1_Click(obj         


        
相关标签:
3条回答
  • 2021-01-29 12:23

    I think you just need to use Text property of abc label;

    abc.Text = r1.Next(b).ToString();
    
    0 讨论(0)
  • 2021-01-29 12:25

    Of course you ain't gonna assign integer to label..

    You have to set the text property of the label

    abc.Text = r1.Next(b).ToString();
    
    0 讨论(0)
  • 2021-01-29 12:34

    You are assigning the value to the label not the text of the label. This line

    abc = r1.Next(b);
    

    should be

    abc.Text = r1.Next(b).ToString();
    

    The error is trying to tell you that it cannot convert an int object into a Label object

    0 讨论(0)
提交回复
热议问题