读书人

WIN程序,怎么动态绑定图片

发布时间: 2012-01-09 21:05:42 作者: rapoo

WIN程序,如何动态绑定图片?
ListBox里要求根据数据库给定的值,动态绑定四张图片,我原来是通过反射来动态加载程序集中嵌入资源的四张图片.可是总提示出错.因此还发贴问过,原贴:http://community.csdn.net/Expert/topic/5643/5643689.xml?temp=1.278102E-03
现在还有别的什么办法可以实现动态绑定嵌入资源的四张图片吗?
哪位朋友帮我解决,一起结贴给分.谢谢.

[解决办法]
一种思路:图片采用文件,加载采用路径就可以了
[解决办法]
我的思路同上的
是我的方法
1.得片路用方法置片
string picturePath=UserParameter.ImagePath+this.dataCenter1.CurrentDataRow[ "service_empl_sfz "].ToString().Trim()+ "e.jpg ";
ShowPicture(this.panel1,this.pictureBox1,picturePath,PictureBoxSizeMode.StretchImage);

2.相方法
#region 得人片料
/// <summary>
/// 得指定人的DataTable型的片料
/// </summary>
/// <param name= "emplIndex "> 系 </param>
/// <param name= "imageFilename "> 所的片文件路和名 </param>
/// <returns> DataTable </returns>
public static DataTable getPersonnelImage(string emplIndex,string imageFileName)
{
DataTable result=new DataTable( "Hr_Report_IndexVsImage ");
DataColumn dc=new DataColumn( "empl_index ",typeof(string));
result.Columns.Add(dc);
dc=new DataColumn( "empl_image ",typeof(Byte[]));
result.Columns.Add(dc);
byte[] image=getImage(imageFileName);
if(image!=null)
{
DataRow dr=result.NewRow();
dr[0]=emplIndex;
dr[1]=image;
result.Rows.Add(dr);
}
return result;
}

/// <summary>
/// 根文件名,取象文件byte[]值
/// </summary>
/// <param name= "fileName "> 图像的文件名 </param>
/// <returns> 象文件的byte[]型的值;否,null </returns>
private static byte[] getImage(string fileName)
{
byte[] result=null;
try
{
if(File.Exists(fileName))
{
FileStream fs = new FileStream(fileName, FileMode.Open); // 创建文件流
BinaryReader br = new BinaryReader(fs); // 创建二进制读取器

result=br.ReadBytes((int)br.BaseStream.Length);

br = null;
fs = null;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message+ "\r\n\r\n "+fileName, "Error ",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return result;
}
#endregion

读书人网 >C#

热点推荐