Zrobiłem sobie prostego wisielca z przygotowanymi słowami (wszystkie 7 literowe) i wpadłem na pomysł żeby po przyciśnięciu przycisku "Sprawdź" tekst który znajdował się w textBoxie znikał żeby nie trzeba było go za każdym razem kasować. Czy ktoś pomógł by mi powiedzieć jak to zrobić albo dać jakiś poradnik gdzie było by to wytłumaczone
Tutaj link do prototypu"gry":
https://megawrzuta.pl/download/3ce6c7fc6b82f9bb9d54a3508b7f1544.html
a tu kod jeżeli by ktoś chciał :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Wisielec
{
public partial class Form1 : Form
{
string slowo;
int ile_pudel = 0;
private void losuj_slowo()
{
pictureBox1.Visible = false;
pictureBox2.BringToFront();
button3.BringToFront();
string[] slowa = { "Krokusy", "Liliput", "Marchew", "Selerek", "Krakers", "Klakier", };
int ile_slow = slowa.Length;
Random gen = new Random();
int indeks_slowa = gen.Next(0, ile_slow);
slowo = slowa[indeks_slowa];
label1.Text = Convert.ToString(slowo[0]);
label7.Text = Convert.ToString(slowo[6]);
}
public Form1()
{
InitializeComponent();
losuj_slowo();
}
private void label4_Click(object sender, EventArgs e)
{
}
private void wygrana()
{
if (label2.Text != "_")
{
if (label3.Text != "_")
{
if (label4.Text != "_")
{
if (label5.Text != "_")
{
if (label6.Text != "_")
{
pictureBox1.Image = Wisielec.Properties.Resources.wygrana;
button2.Visible = true;
}
}
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (ile_pudel < 6)
{
string litera = textBox1.Text;
bool czy_trafiony = false;
int gdzie_trafiony = 0;
for (int i = 1; i < 6; i++)
{
if (Convert.ToString(slowo[i]) == litera)
{
czy_trafiony = true;
gdzie_trafiony = i;
if (gdzie_trafiony == 1) { label2.Text = litera; }
if (gdzie_trafiony == 2) { label3.Text = litera; }
if (gdzie_trafiony == 3) { label4.Text = litera; }
if (gdzie_trafiony == 4) { label5.Text = litera; }
if (gdzie_trafiony == 5) { label6.Text = litera; }
}
}
if (czy_trafiony == false)
{
pictureBox1.Visible = true;
ile_pudel = ile_pudel + 1;
if (ile_pudel == 1) { pictureBox1.Image = Wisielec.Properties.Resources.r3_1; }
if (ile_pudel == 2) { pictureBox1.Image = Wisielec.Properties.Resources.r3_2; }
if (ile_pudel == 3) { pictureBox1.Image = Wisielec.Properties.Resources.r3_3; }
if (ile_pudel == 4) { pictureBox1.Image = Wisielec.Properties.Resources.r3_4; }
if (ile_pudel == 5) { pictureBox1.Image = Wisielec.Properties.Resources.r3_5; }
if (ile_pudel == 6)
{
pictureBox1.Image = Wisielec.Properties.Resources.przegrana;
button2.Visible = true;
}
}
wygrana();
}
}
private void button2_Click(object sender, EventArgs e)
{
losuj_slowo();
label2.Text = "_";
label3.Text = "_";
label4.Text = "_";
label5.Text = "_";
label6.Text = "_";
ile_pudel = 0;
button2.Visible = false;
pictureBox1.Image = null;
}
private void button3_Click(object sender, EventArgs e)
{
pictureBox3.BringToFront();
button5.BringToFront();
pictureBox2.Visible = false;
button3.Visible = false;
button5.Visible = true;
pictureBox3.Visible = true;
}
private void button5_Click(object sender, EventArgs e)
{
Random tlo = new Random();
int jakie_tlo = tlo.Next(0, 5);
if (jakie_tlo == 0)
{
pictureBox4.Image = Wisielec.Properties.Resources.Bez_tytułu1;
}
else if (jakie_tlo == 1)
{
pictureBox4.Image = Wisielec.Properties.Resources.t1;
}
else if (jakie_tlo == 2)
{
pictureBox4.Image = Wisielec.Properties.Resources.t2;
}
else if (jakie_tlo == 3)
{
pictureBox4.Image = Wisielec.Properties.Resources.t3;
}
else if (jakie_tlo == 4)
{
pictureBox4.Image = Wisielec.Properties.Resources.t4;
}
else if (jakie_tlo == 5)
{
pictureBox4.Image = Wisielec.Properties.Resources.t5;
}
if (jakie_tlo == 0)
{
label1.Image = Wisielec.Properties.Resources.Bez_tytułu1;
label2.Image = Wisielec.Properties.Resources.Bez_tytułu1;
label3.Image = Wisielec.Properties.Resources.Bez_tytułu1;
label4.Image = Wisielec.Properties.Resources.Bez_tytułu1;
label5.Image = Wisielec.Properties.Resources.Bez_tytułu1;
label6.Image = Wisielec.Properties.Resources.Bez_tytułu1;
label7.Image = Wisielec.Properties.Resources.Bez_tytułu1;
}
else if (jakie_tlo == 1)
{
label1.Image = Wisielec.Properties.Resources.t1;
label2.Image = Wisielec.Properties.Resources.t1;
label3.Image = Wisielec.Properties.Resources.t1;
label4.Image = Wisielec.Properties.Resources.t1;
label5.Image = Wisielec.Properties.Resources.t1;
label6.Image = Wisielec.Properties.Resources.t1;
label7.Image = Wisielec.Properties.Resources.t1;
}
else if (jakie_tlo == 2)
{
label1.Image = Wisielec.Properties.Resources.t2;
label2.Image = Wisielec.Properties.Resources.t2;
label3.Image = Wisielec.Properties.Resources.t2;
label4.Image = Wisielec.Properties.Resources.t2;
label5.Image = Wisielec.Properties.Resources.t2;
label6.Image = Wisielec.Properties.Resources.t2;
label7.Image = Wisielec.Properties.Resources.t2;
}
else if (jakie_tlo == 3)
{
label1.Image = Wisielec.Properties.Resources.t3;
label2.Image = Wisielec.Properties.Resources.t3;
label3.Image = Wisielec.Properties.Resources.t3;
label4.Image = Wisielec.Properties.Resources.t3;
label5.Image = Wisielec.Properties.Resources.t3;
label6.Image = Wisielec.Properties.Resources.t3;
label7.Image = Wisielec.Properties.Resources.t3;
}
else if (jakie_tlo == 4)
{
label1.Image = Wisielec.Properties.Resources.t4;
label2.Image = Wisielec.Properties.Resources.t4;
label3.Image = Wisielec.Properties.Resources.t4;
label4.Image = Wisielec.Properties.Resources.t4;
label5.Image = Wisielec.Properties.Resources.t4;
label6.Image = Wisielec.Properties.Resources.t4;
label7.Image = Wisielec.Properties.Resources.t4;
}
else if (jakie_tlo == 5)
{
label1.Image = Wisielec.Properties.Resources.t5;
label2.Image = Wisielec.Properties.Resources.t5;
label3.Image = Wisielec.Properties.Resources.t5;
label4.Image = Wisielec.Properties.Resources.t5;
label5.Image = Wisielec.Properties.Resources.t5;
label6.Image = Wisielec.Properties.Resources.t5;
label7.Image = Wisielec.Properties.Resources.t5;
}
pictureBox3.Visible = false;
button5.Visible = false;
button4.Visible = true;
}
private void pictureBox4_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
pictureBox3.Visible = true;
button5.Visible = true;
button4.Visible = false;
}
}
}