TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Charlotte Lunessa
NA
5
600
Hangman Character Issue
Apr 14 2016 5:28 PM
This is for a class, but our teacher had to go on medical leave, and the substitute doesn't know anything about coding, so I am completely stuck. I created dynamic labels in a groupbox for the words that are randomly selected, and there are buttons that are not dynamic with the letters on them. I am not sure how to reference the "non-existent" labels, and I could not find anything that said that you can reference all items in a groupbox at once. The program will not load, seeing as it is an error to reference specific dynamic elements. I need to find a way to check the letter that is clicked against the letter that should be in the label (created via an array). I have been fighting with this for the past week, so any help will be appreciated. Thank you.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Hangman
{
public partial class frmHang : Form
{
public frmHang()
{
InitializeComponent();
}
Random rndThing = new Random((int)DateTime.Now.Ticks);
string[] strWords = new string[10]
{
"computer", "desktop", "hardware", "keyboard", "mouse", "glasses", "tower", "samsung", "lenovo", "pencil"
};
private void frmHang_Load(object sender, EventArgs e)
{
}
string strWordToGuess;
private void btnStart_Click(object sender, EventArgs e)
{
Random rndWord = new Random();
strWordToGuess = strWords[rndThing.Next(0, 10)];
grpWordLetters.Controls.Clear();
char[] wordChars = strWordToGuess.ToCharArray();
int intWordLength = wordChars.Length;
int refer = grpWordLetters.Width / intWordLength;
for (int i = 0; i < intWordLength; i++)
{
Label lblCharacter = new Label();
lblCharacter.Text = "_";
lblCharacter.Location = new Point(10 + i * refer, grpWordLetters.Height - 30);
lblCharacter.Parent = grpWordLetters;
lblCharacter.BringToFront();
}
}
private void btnA_Click(object sender, EventArgs e)
{
btnA.Enabled=false;
}
}
}
Reply
Answers (
4
)
how to save extracted data in xml file
how to add value to combobox from variable