使用listbox然后把图象画上去如下: private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
Image myImage = new Bitmap(listBox1.Items[e.Index].ToString());//这里的图象可以去数据库或其他地方取
Rectangle rectImage = new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2 , e.Bounds.Height - 2);
rectImage.Width = (int) Math.Round(myImage.Width * ((double) e.Bounds.Height / myImage.Height));
e.Graphics.DrawImage(myImage, rectImage);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
// Draws the rectangle around the selected item.
e.DrawFocusRectangle();
}
{
try
{
Image myImage = new Bitmap(listBox1.Items[e.Index].ToString());//这里的图象可以去数据库或其他地方取
Rectangle rectImage = new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2 , e.Bounds.Height - 2);
rectImage.Width = (int) Math.Round(myImage.Width * ((double) e.Bounds.Height / myImage.Height));
e.Graphics.DrawImage(myImage, rectImage);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
// Draws the rectangle around the selected item.
e.DrawFocusRectangle();
}
解决方案 »
- 关于日期
- C#公共变量
- C# 需要引用user32.dll gdi.dll kernel.dll 如何得知 其中函数的完整签名和使用方法呢?
- windows应用程序与C#组件编程有什么区别
- 通过PostBackUrl提交并跳转页面后,如何接受到ascx控件中的TextBox值
- 关于.net framework 源代码问题
- 打包 数据库 配置文件 有高手 心得的高手们进~!小弟急~!在线等待~!!!
- 高分求 水晶报表 for .net的电子书籍
- 如果一个界面上有一个ImageList,C#能不能向Delphi那样不用代码就调用他?
- 如何将字符串型"20041212"转换为日期型的“2004.12.12”
- 高分请教:如何将多个只有sheet1的Excel文件合并成一个有多个sheet的Excel文件?
- 关于正则表达式!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
大哥你有没有搞错?你要实现什么功能?
难道就不能优化一下?
你说的以前其他语言是什么语言??
那么也许是用了form的BackgroundImage属性~~这就是显示速度慢的原因。
我给个例子给你,用GDI+方式显示背景图片,我试了一下,速度快很多,在我的系统里我加载了100个透明的Label~~也只是首次加载稍微有点闪烁而已。test.jpg放在编译后的可执行文件同一个目录,Enjoy it!namespace GDIBack
{
using System;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Reflection; public class ImagesSample : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components; private System.Drawing.Brush backgroundBrush;
public ImagesSample()
{
InitializeComponent(); Image backgroundImage;
backgroundImage = new Bitmap("test.jpg");
backgroundBrush = new TextureBrush(backgroundImage); } protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(backgroundBrush, ClientRectangle);
}
/// <summary>
/// 清理正在使用的所有资源。
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
} /// <summary>
/// 设计器支持所必需的方法,不要使用
/// 代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent ()
{
//
// ImagesSample
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(742, 472);
this.Name = "ImagesSample";
this.Text = "GDI+ 背景示例"; } /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
public static void Main()
{
Application.Run(new ImagesSample());
}
}
}