如何在Windows窗体中更改窗体图标

时间:2013-11-07 09:14:25

标签: c# visual-studio-2010 windows-forms-designer

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

                  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();
                }
            }
        }
    }

6 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

您需要执行以下步骤

  1. 添加图标以重新分配项目文件
  2. 而不是将创建的资源用于您的图标属性。
  3.   

    Icon = Resources.adobe_reader_icon;

答案 2 :(得分:0)

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

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

答案 3 :(得分:0)

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

如果是这样,您应该可以使用this.Icon = ...

进行设置

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

答案 4 :(得分:0)

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

答案 5 :(得分:-1)

  1. 第一个解决方案,然后添加项目的属性。ico文件
  2. 然后打开想要的表单图标
  3. 在Form属性中,您可以找到图标字段
  4. 您可以在其中更改Windows窗体的图标。