Windows Forms를 그냥 속이고 버튼을 클릭 한 다음 플레이어에게 임의의 카드 두 장을주고 싶지만 버튼을 클릭하면 레이블이 비어 있습니다. 값을 문자열로 전달하는 방법은 무엇입니까? 임의의 카드 가져 오기 및 레이블 변경
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void DealTheCardsButton_Click(object sender, EventArgs e)
{
TheCards theCards = new TheCards();
CardOneLabel.Text = theCards.card1;
}
}
public class TheCards
{
public TheCards()
{
Cards = new List<string>();
Cards.Add("1");
Cards.Add("2");
Cards.Add("3");
Cards.Add("4");
}
public List<string> Cards { get; set; }
public string card1;
public string card2;
public string cardTest = "hej";
public void GiveTwoRandomCardsFromCardsList()
{
Random random = new Random();
int slumptal = random.Next(0, 4);
card1 = Cards[1];
bool flag = false;
while (!flag)
{
Random random2 = new Random();
int slumptal2 = random2.Next(0, 4);
if (slumptal != slumptal2)
{
card2 = Cards[slumptal2];
flag = true;
}
}
}
}
나는 그것이 작동 거기에 하드 코딩 된 값을 문자열로 CardOneLabel.Text
을 변경 호출하면
string card1
과
string card2
의 값을 변경하지 않는 것 같습니다. 지금과 같이 버튼을 클릭하면 레이블의 값이 아무 것도 아닌 것으로 변경됩니다 (비어 있음).
레이블 값을 임의의 카드 값으로 어떻게 바꿀 수 있습니까?
매력 작품! 내 무작위 대결에 대한 큰 감사. 그것을 무작위로 줄입니다. 그것이 지금은 같은 두 개의 카드를 얻을 수 없어 작동하지만 난 당신이 점점 1 랜덤으로 줄이고 이해가 :) – darrrrUC