用C#写下代码
怎么将VS2008右边菜单(Resources 即资源)中的图片显示在Picturebox中,谢谢!!!!

解决方案 »

  1.   

    在资源里面添加一个图片
    在PictureBox的Image属性里面设置图片为资源里面的。打开 from.design.cs,里面有 IDE 为你写的加载的代码。
      

  2.   


    this.pictureBox1.Image=命名空间.Properties.Resources.图片名;
      

  3.   

    我写了如下一段程序,可是图片还是不按照我的要求改变,请大家帮忙分析下,谢谢
        private void pictureBox12_Click(object sender, EventArgs e)
            {
                ///设置连接字符串
                string connectionString = "data source=localhost;user id=sa;pwd=12345678;database=RailWay;";
                ///创建SqlConnection类的实例,用于连接SQL Server 数据库          
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    try
                    {                    connection.Open();
                        SqlCommand command = new SqlCommand("select Wind_Speed from WS_Real", connection);
                        SqlDataReader reader = command.ExecuteReader();
                        
                        while (reader.Read())
                        {
                            int Wind_Speed = reader.GetInt32(0);                        if (Wind_Speed <= 15)
                            {
                                netState = 0;
                                this.A_W1.Image = Image.FromFile("WindowsFormsApplication1.Properties.Resources\\红18x18.gif");                        }
                            else if ( Wind_Speed <= 20)
                            {
                                netState = 1;                            this.A_W1.Image = Image.FromFile("WindowsFormsApplication1.Properties.Resources\\灰18x18.gif");                        }                        else if ( Wind_Speed <= 25)
                            {
                                netState = 2;                            this.A_W1.Image = Image.FromFile("WindowsFormsApplication1.Properties.Resources\\绿18x18.gif");                        }                        else if (  Wind_Speed <= 30)                        { netState = 3; }                        else if (Wind_Speed <= 12000)
                            {
                                netState = 4;
                            }                    }                }                catch(Exception s)
                    {
                        Console.WriteLine(s.Message);
                    }
                    finally                { connection.Close(); }
                }
              
             
                    
            }   
      

  4.   

    Assembly assembly = GetType().Assembly;
    Bitmap bmp = new Bitmap(assembly.GetManifestResourceStream(Test1.Resources.1.jpg));//Test1是项目名
    pictureBox1.Image = bmp;