С#

  • Автор темы SashaT
  • Дата начала
S

SashaT

#1
if (radioButton1.Checked == true)
{
MessageLabel.Font = radioButton1.Font;
}
else if (radioButton2.Checked == true)
{
MessageLabel.Font = radioButton2.Font;
}
else if (radioButton3.Checked == true)
{
MessageLabel.Font = radioButton3.Font;
}
if (radioButton4.Checked == true)
{
MessageLabel.ForeColor = radioButton4.ForeColor;
}
else if (radioButton5.Checked == true)
{
MessageLabel.ForeColor = radioButton5.ForeColor;
}
else if (radioButton6.Checked == true)
{
MessageLabel.ForeColor = radioButton6.ForeColor;
}

Как написать этот код Более Коротко?
 
S

SashaT

#2
Все уже Сделал)) Else можно было сносить и true тоже))
а еще такой вопрос Как в exe файл вшить картинку?
 
S

SashaT

#3
case 1: pictureBox1.BackgroundImage = Properties.Resources.card11; break;
case 2: pictureBox1.BackgroundImage = Properties.Resources.card12; break;
case 3: pictureBox1.BackgroundImage = Properties.Resources.card13; break;
case 4: pictureBox1.BackgroundImage = Properties.Resources.card14; break;
case 5: pictureBox1.BackgroundImage = Properties.Resources.card15; break;
case 6: pictureBox1.BackgroundImage = Properties.Resources.card16; break;
case 7: pictureBox1.BackgroundImage = Properties.Resources.card17; break;
case 8: pictureBox1.BackgroundImage = Properties.Resources.card18; break;
case 9: pictureBox1.BackgroundImage = Properties.Resources.card19; break;
case 10: pictureBox1.BackgroundImage = Properties.Resources.card21; break;
case 11: pictureBox1.BackgroundImage = Properties.Resources.card22; break;
case 12: pictureBox1.BackgroundImage = Properties.Resources.card23; break;
case 13: pictureBox1.BackgroundImage = Properties.Resources.card24; break;
case 14: pictureBox1.BackgroundImage = Properties.Resources.card25; break;
case 15: pictureBox1.BackgroundImage = Properties.Resources.card26; break;
case 16: pictureBox1.BackgroundImage = Properties.Resources.card27; break;
case 17: pictureBox1.BackgroundImage = Properties.Resources.card28; break;
case 18: pictureBox1.BackgroundImage = Properties.Resources.card29; break;
case 19: pictureBox1.BackgroundImage = Properties.Resources.card31; break;
case 20: pictureBox1.BackgroundImage = Properties.Resources.card32; break;
case 21: pictureBox1.BackgroundImage = Properties.Resources.card33; break;
case 22: pictureBox1.BackgroundImage = Properties.Resources.card34; break;
case 23: pictureBox1.BackgroundImage = Properties.Resources.card35; break;

case 24: pictureBox1.BackgroundImage = Properties.Resources.card36; break;
case 25: pictureBox1.BackgroundImage = Properties.Resources.card37; break;
case 26: pictureBox1.BackgroundImage = Properties.Resources.card38; break;
case 27: pictureBox1.BackgroundImage = Properties.Resources.card39; break;
case 28: pictureBox1.BackgroundImage = Properties.Resources.card41; break;
case 29: pictureBox1.BackgroundImage = Properties.Resources.card42; break;
case 30: pictureBox1.BackgroundImage = Properties.Resources.card43; break;

Вот вроде вшил но просят чтобы без case это возможно?
 
B

BoYar

#4
case 1: pictureBox1.BackgroundImage = Properties.Resources.card11; break;
case 2: pictureBox1.BackgroundImage = Properties.Resources.card12; break;
case 3: pictureBox1.BackgroundImage = Properties.Resources.card13; break;
case 4: pictureBox1.BackgroundImage = Properties.Resources.card14; break;
case 5: pictureBox1.BackgroundImage = Properties.Resources.card15; break;
case 6: pictureBox1.BackgroundImage = Properties.Resources.card16; break;
case 7: pictureBox1.BackgroundImage = Properties.Resources.card17; break;
case 8: pictureBox1.BackgroundImage = Properties.Resources.card18; break;
case 9: pictureBox1.BackgroundImage = Properties.Resources.card19; break;
case 10: pictureBox1.BackgroundImage = Properties.Resources.card21; break;
case 11: pictureBox1.BackgroundImage = Properties.Resources.card22; break;
case 12: pictureBox1.BackgroundImage = Properties.Resources.card23; break;
case 13: pictureBox1.BackgroundImage = Properties.Resources.card24; break;
case 14: pictureBox1.BackgroundImage = Properties.Resources.card25; break;
case 15: pictureBox1.BackgroundImage = Properties.Resources.card26; break;
case 16: pictureBox1.BackgroundImage = Properties.Resources.card27; break;
case 17: pictureBox1.BackgroundImage = Properties.Resources.card28; break;
case 18: pictureBox1.BackgroundImage = Properties.Resources.card29; break;
case 19: pictureBox1.BackgroundImage = Properties.Resources.card31; break;
case 20: pictureBox1.BackgroundImage = Properties.Resources.card32; break;
case 21: pictureBox1.BackgroundImage = Properties.Resources.card33; break;
case 22: pictureBox1.BackgroundImage = Properties.Resources.card34; break;
case 23: pictureBox1.BackgroundImage = Properties.Resources.card35; break;

case 24: pictureBox1.BackgroundImage = Properties.Resources.card36; break;
case 25: pictureBox1.BackgroundImage = Properties.Resources.card37; break;
case 26: pictureBox1.BackgroundImage = Properties.Resources.card38; break;
case 27: pictureBox1.BackgroundImage = Properties.Resources.card39; break;
case 28: pictureBox1.BackgroundImage = Properties.Resources.card41; break;
case 29: pictureBox1.BackgroundImage = Properties.Resources.card42; break;
case 30: pictureBox1.BackgroundImage = Properties.Resources.card43; break;

Вот вроде вшил но просят чтобы без case это возможно?
конечно возможно))
if переменная == 1 pictureBox1.BackgroundImage = Properties.Resources.card11;
if переменная == 2 pictureBox1.BackgroundImage = Properties.Resources.card12;
ну и так далее по тексту))