pictureBox如何显示资源中的图片 用C#写下代码怎么将VS2008右边菜单(Resources 即资源)中的图片显示在Picturebox中,谢谢!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在资源里面添加一个图片在PictureBox的Image属性里面设置图片为资源里面的。打开 from.design.cs,里面有 IDE 为你写的加载的代码。 this.pictureBox1.Image=命名空间.Properties.Resources.图片名; 我写了如下一段程序,可是图片还是不按照我的要求改变,请大家帮忙分析下,谢谢 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(); } } } Assembly assembly = GetType().Assembly;Bitmap bmp = new Bitmap(assembly.GetManifestResourceStream(Test1.Resources.1.jpg));//Test1是项目名pictureBox1.Image = bmp; 备份和还原SQL2008的数据库 采用C#代码 不是SQL2000看清楚了 c#做WinFro进度条(ProgressBar)怎么弄? C#通过执行Sql语句存储数据,但出现串数问题。 字符串FOR循环问题!!!!!!!! ClearPool()的问题 关于白马非马的证明 C#中的继承 如何在crystal report 中画标准表格,在线等待 关于Remoting的问题,请高手解答。 请教一个匹配替换的问题? c#开发出现“未处理System.TypeLoadException” 如何获得输入法输入的汉字,字母
在PictureBox的Image属性里面设置图片为资源里面的。打开 from.design.cs,里面有 IDE 为你写的加载的代码。
this.pictureBox1.Image=命名空间.Properties.Resources.图片名;
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(); }
}
}
Bitmap bmp = new Bitmap(assembly.GetManifestResourceStream(Test1.Resources.1.jpg));//Test1是项目名
pictureBox1.Image = bmp;