0

请我需要帮助我正在为刽子手游戏编写代码,我只想更改表单的图标,我尝试使用 icon 属性但它不再起作用,请问我该怎么做,并且我也做了以下项目-->属性--->图标和清单,但它也不起作用这是我的游戏代码,它完美地工作:

                  private void button1_Click(object sender, EventArgs e)
            {

                stage_count++;//strat from stage 1

               if (!int.TryParse(textBox1.Text.ToString(), out value))
                  return;//if user inter non_integer value do no thing and wait for new entry

               if (key ==value )//directly if user guesses the key he/she wins the game 
               {
                   //view the seventh picture in hangman game
                   button1.Enabled = false;
                   textBox1.Text = "";
                   textBox1.Enabled = false;
                   pictureBox7.Visible = true;
                   pictureBox1.Visible = false;
                   pictureBox2.Visible = false;
                   pictureBox3.Visible = false;
                   pictureBox4.Visible = false;
                   pictureBox5.Visible = false;
                   pictureBox6.Visible = false;

                   groupBox1.Visible = true;

                   label1.Text = "Great... You Got It ^_^ ";
               }




                   if (key > value)//guide the user to the correct answer
                        label1.Text = "Should Be Greater than" + value.ToString();

                   if (key < value)//guide the user to the correct answer
                        label1.Text = "Should Be Less than" + value.ToString();
                   if (key != value)
                   {
                       switch (stage_count)
                       {//this switch statement used to do some thing in each stage
                           case 1:
                               //view the first picture in hangman game
                               pictureBox1.Visible = true;
                               pictureBox2.Visible = false;
                               pictureBox3.Visible = false;
                               pictureBox4.Visible = false;
                               pictureBox5.Visible = false;
                               pictureBox6.Visible = false;
                               pictureBox7.Visible = false;
                               break;
                           case 2:
                               //view the second  picture in hangman game
                               pictureBox1.Visible = false;
                               pictureBox2.Visible = true;
                               pictureBox3.Visible = false;
                               pictureBox4.Visible = false;
                               pictureBox5.Visible = false;
                               pictureBox6.Visible = false;
                               pictureBox7.Visible = false;

                               break;
                           case 3:
                               //view the third picture in hangman game
                               pictureBox1.Visible = false;
                               pictureBox2.Visible = false;
                               pictureBox3.Visible = true;
                               pictureBox4.Visible = false;
                               pictureBox5.Visible = false;
                               pictureBox6.Visible = false;
                               pictureBox7.Visible = false;

                               break;
                           case 4:
                               //view the fourth picture in hangman game
                               pictureBox1.Visible = false;
                               pictureBox2.Visible = false;
                               pictureBox3.Visible = false;
                               pictureBox4.Visible = true;
                               pictureBox5.Visible = false;
                               pictureBox6.Visible = false;
                               pictureBox7.Visible = false;

                               break;
                           case 5:
                               //view the fifth  picture in hangman game
                               pictureBox1.Visible = false;
                               pictureBox2.Visible = false;
                               pictureBox3.Visible = false;
                               pictureBox4.Visible = false;
                               pictureBox5.Visible = true;
                               pictureBox6.Visible = false;
                               pictureBox7.Visible = false;

                               break;

                           default:
                               //view the sixth picture in hangman game
                               //it's the last try so diable the button and show the result
                               button1.Enabled = false;
                               textBox1.Text = "";
                               textBox1.Enabled = false;
                               groupBox1.Visible = true;
                               label1.Text = "YOU  LOSE ,, IT  WAS :    " + key.ToString();
                               pictureBox1.Visible = false;
                               pictureBox2.Visible = false;
                               pictureBox3.Visible = false;
                               pictureBox4.Visible = false;
                               pictureBox5.Visible = false;
                               pictureBox6.Visible = true;
                               pictureBox7.Visible = false;

                               break;



                       }//end switch
                       //to make empty focused textbox 
                       textBox1.Text = "";
                       textBox1.Focus();


                   }//end if   


            }

            private void groupBox1_Enter(object sender, EventArgs e)
            {



            }

            private void radioButton1_CheckedChanged(object sender, EventArgs e)
            {// if user want to playe new game the programm must enables the important controls and 
                //make the visible property equals to false for all the pictures boxes

                if (radioButton1.Checked == true)
                {
                    stage_count = 0;
                     key = (1 + obj.Next(99));
                    textBox1.Enabled = true;
                    textBox1.Text = "";
                    textBox1.Focus();
                    button1.Enabled = true;
                    label1.Text = "Guess a number btween 1-100";
                    pictureBox1.Visible = false;
                    pictureBox2.Visible = false;
                    pictureBox3.Visible = false;
                    pictureBox4.Visible = false;
                    pictureBox5.Visible = false;
                    pictureBox6.Visible = false;
                    pictureBox7.Visible = false;

                    groupBox1.Visible = false;
                    radioButton1.Checked = false;
                }
            }

            private void radioButton2_CheckedChanged(object sender, EventArgs e)
            {
                // if user won't to play again just close it 
                if (radioButton2.Checked == true)
                {
                    radioButton2.Checked = false;
                    this.Close();
                }
            }
        }
    }
4

6 回答 6

1

转到属性窗口并使用您自己的图标更改“图标”属性。

于 2013-11-07T09:16:08.993 回答
0

您需要执行以下步骤

  1. 将您的图标添加到项目的资源文件中
  2. 比将创建的资源分配给您的图标属性。

图标 = Resources.adobe_reader_icon;

于 2013-11-07T09:18:09.403 回答
0

您必须在项目的属性中设置它。

如果您在 VisualStudio 中按 F5 启动应用程序,但未出现图标,请查看 Debug-(Release) 目录。应该有正确的图标

于 2013-11-07T09:19:29.443 回答
0

只有在以下情况下才会显示表单的图标:
- ControlBox 为真
- FormBorderStyle 不为None
- 文本不为空

如果是这样,那么您应该可以将其设置为this.Icon = ...

该图标也应可用作项目资源。为此,您只需编辑表单Icon属性,然后在以下对话框中从.ico文件中导入图标。

于 2013-11-07T09:20:37.097 回答
0

<pre>
application root directory
application resources directory  **LIKE** ../../resources/dropbox.ico 
this.Icon = new System.Drawing.Icon("../../dropbox.ico");
</pre>  

于 2019-12-04T06:42:27.237 回答
-1
  1. 第一个解决方案,然后是项目的属性添加 .ico 文件
  2. 然后打开你想要的表格图标
  3. 在表单属性中,您可以找到图标字段
  4. 在那里你可以改变你的 Windows 窗体的图标。
于 2019-09-18T06:08:14.730 回答