Example #1
0
        public void DrawAnswers(WordBank bank)
        {
            char[,] grid = bank.AnswerKey();
            if (grid == null)
            {
                MessageBox.Show("No generated word search yet!", "Generate first!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                graphics.Clear(Color.White);
                float boxwidth = this.Width / grid.GetLength(0);
                float boxheight = this.Height / grid.GetLength(1);
                Pen basic = new Pen(Brushes.Black, 2);
                Font font = new System.Drawing.Font("Consolas", boxheight);
                for (int x = 0; x < grid.GetLength(0); x++)
                {
                    for (int y = 0; y < grid.GetLength(1); y++)
                    {
                        graphics.DrawRectangle(basic, x * boxwidth, y * boxheight, boxwidth, boxheight);
                        char current = grid[x, y];
                        SizeF size = graphics.MeasureString(current.ToString(), font);
                        float centerx = (x * boxwidth) + (boxwidth / 2);
                        float centery = (y * boxheight) + (boxheight / 2);
                        float truex = centerx - (size.Width / 2);
                        float truey = centery - (size.Height / 2);
                        graphics.DrawString(current.ToString(), font, Brushes.Black, truex, truey);

                    }
                }
            }
        }
Example #2
0
        private void btnGen_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count > 0)
            {
                //string[] words;
                //if (listBox1.SelectedItems.Count > 0 && listBox1.SelectedItems.Count<=15)
                //{
                //    words = new string[listBox1.SelectedItems.Count];
                //        for (int i = 0; i < listBox1.SelectedItems.Count; i++)
                //            words[i] = (string)listBox1.SelectedItems[i];
                //}
                //else
                //{
                //    words = new string[listBox1.Items.Count];
                //    for (int i = 0; i < words.Length; i++)
                //        words[i] = (string)listBox1.Items[i];
                //}

                string[] words = new string[listBox1.Items.Count];

                for (int i = 0; i < words.Length; i++)
                    words[i] = (string)listBox1.Items[i];

                this.bank = new WordBank(words, true , 15);
                lstWordsInGrid.Items.Clear();
                foreach (var items in bank.SelectedWords)
                    lstWordsInGrid.Items.Add(items);
                this.grid = this.bank.Generate();
                wordSearch1.DrawBank(grid);
            }
            else
            {
                MessageBox.Show("Please add words to the word bank!", "No word", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }