using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Study_MyAlbumEditor
{
public partial class Form1 : Form
{
//Dictionary<int, string> PA = new Dictionary<int, string>();
List<string> PA = new List<string>();

private Rectangle _drawRect = new Rectangle(0, 0, 45, 45);

private SolidBrush _textBrush = new SolidBrush(SystemColors.WindowText);

public Form1()
{
InitializeComponent();
// 1.
//int i = 0;
//foreach (string str in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)))
//{
// PA.Add(i, str);
// i++;
//}
//BindingSource bs = new BindingSource();
//bs.DataSource = PA;
//listBox1.DataSource = bs;
////listBox1.DataSource = PA;
//listBox1.DisplayMember = "Value";

// 2.
PA.AddRange(Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)));
listBox1.DataSource = PA;

comboBox1.DataSource = PA;
}

private void thumbToolStripMenuItem_Click(object sender, EventArgs e)
{
thumbToolStripMenuItem.Checked = !thumbToolStripMenuItem.Checked;
if (thumbToolStripMenuItem.Checked)
{
listBox1.DrawMode = DrawMode.OwnerDrawVariable;
comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
}
else
{
listBox1.DrawMode = DrawMode.Normal;
listBox1.ItemHeight = 16;
comboBox1.DrawMode = DrawMode.Normal;
comboBox1.ItemHeight = 16;
}
}

private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = 45 + 2;
e.ItemWidth = 45 + 2 + (int)e.Graphics.MeasureString(listBox1.Items[e.Index].ToString(), listBox1.Font).Width;

}

private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Rectangle imageRect = e.Bounds;
imageRect.Y += 1;
imageRect.Height = 45;
imageRect.X += 1;
imageRect.Width = 45;

Rectangle textRect = new Rectangle(imageRect.Right + 2, imageRect.Y + ((imageRect.Height - e.Font.Height) / 2), e.Bounds.Width - imageRect.Width - 4, e.Font.Height);
Rectangle fillRect = e.Bounds;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
_textBrush.Color = SystemColors.Highlight;
//g.FillRectangle(_textBrush, textRect);
g.FillRectangle(_textBrush, fillRect);
_textBrush.Color = SystemColors.HighlightText;
}
else
{
_textBrush.Color = SystemColors.Window;
//g.FillRectangle(_textBrush, textRect);
g.FillRectangle(_textBrush, fillRect);
_textBrush.Color = SystemColors.WindowText;
}

Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
try
{
g.DrawImage(Image.FromFile(listBox1.Items[e.Index].ToString()).GetThumbnailImage(45, 45, myCallback, IntPtr.Zero), imageRect);
g.DrawRectangle(Pens.Gray, imageRect);
}
catch (Exception)
{
g.DrawRectangle(Pens.Blue, imageRect);
}

g.DrawString(listBox1.Items[e.Index].ToString(), e.Font, _textBrush, textRect);
}

public bool ThumbnailCallback()
{
return false;
}

private void comboBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = 45 + 2;
e.ItemWidth = 45 + 2 + (int)e.Graphics.MeasureString(comboBox1.Items[e.Index].ToString(), comboBox1.Font).Width;// listBox1.Items[e.Index].ToString(), listBox1.Font).Width;
}

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Rectangle imageRect = e.Bounds;
imageRect.Y += 1;
imageRect.Height = 45;
imageRect.X += 1;
imageRect.Width = 45;

Rectangle textRect = new Rectangle(imageRect.Right + 2, imageRect.Y + ((imageRect.Height - e.Font.Height) / 2), e.Bounds.Width - imageRect.Width - 4, e.Font.Height);
Rectangle fillRect = e.Bounds;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
_textBrush.Color = SystemColors.Highlight;
//g.FillRectangle(_textBrush, textRect);
g.FillRectangle(_textBrush, fillRect);
_textBrush.Color = SystemColors.HighlightText;
}
else
{
_textBrush.Color = SystemColors.Window;
//g.FillRectangle(_textBrush, textRect);
g.FillRectangle(_textBrush, fillRect);
_textBrush.Color = SystemColors.WindowText;
}

Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
try
{
g.DrawImage(Image.FromFile(comboBox1.Items[e.Index].ToString()).GetThumbnailImage(45, 45, myCallback, IntPtr.Zero), imageRect);
g.DrawRectangle(Pens.Gray, imageRect);
}
catch (Exception)
{
g.DrawRectangle(Pens.Blue, imageRect);
}

g.DrawString(comboBox1.Items[e.Index].ToString(), e.Font, _textBrush, textRect);
}
}
}

自绘图片下拉项 combobox listbox的更多相关文章

  1. C#中如何将combox中的下拉项和一个枚举中的各项进行绑定

    实现一个combobox,将其各个下拉项与枚举进行绑定 效果图如下: 代码详解如下: 枚举: public enum StoreSite { /// <summary> /// 未知 // ...

  2. 刷新各ifream当前页,下拉项改变触发事件js,给选中项加背景色js

    <script type="text/javascript" language="javascript"> //刷新框架各页面 function r ...

  3. python: HTML之 鼠标放上去下拉项字体显示不同颜色

    鼠标放上去下拉项字体显示不同颜色 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "h ...

  4. 使用AJAX填充<select>标签下拉项,没有显示指定的option项

    newCarInfo.js代码如下: $(function() {     // 获取燃油种类     url = "basicFuelType_queryAll.action"; ...

  5. Dynamics CRM2013 picklist下拉项行数控制

    CRM2013和前面几个版本相比有了很大的变化,本文中讲述的picklist亦然.CRM2013的picklist效果图如下所示 目前能看到的是会根据下拉内容项的数量不同而显示不同的下拉行数,但有时客 ...

  6. jqgrid 配置分页大小及下拉项

    如何配置分页大小的下拉项?显示效果如下: 通过 rowNum 来设置默认分页大小 通过 rowList 来设置分页下拉.   rowList 的值为一个数组,比如:[10,20,30] $(" ...

  7. Qt下拉对话框 ComboBox的用法

    介绍 ComboBox是Qt的下拉菜单的一个控件,通过下拉菜单选择不同的选项,样式如图: 基本用法 m_ComBox = ui.comboBox; //设置默认显示值的索引,从0开始 m_ComBox ...

  8. 下拉框combobox用法&级联餐单

    如果下来内容不用后台取数据,直接写死的话不用url属性,直接用data即可: <input id="orderstate" name="orderstate&quo ...

  9. multiselect获取选中的多个下拉项的值(逗号分割的字符串)

    /*传入下拉select标签*/ function get_selected(mslt_employees) { var emplo =mslt_employees.multiselect(" ...

随机推荐

  1. QT环境下实现UI界面的“拼图游戏”

    main.cpp #include "mainwindow.h" #include <QApplication> int main(int argc, char *ar ...

  2. CDMA学习

    1.关于RC:http://www.mscbsc.com/askpro/question74915 2.CDMA知识要点:http://wenku.baidu.com/view/d4511442a89 ...

  3. focusSNS学习笔记

    FocusSNS是一个社交类型的网站架构 系统的加载过程 所有的分发都从RouteController开始 @RequestMapping(value={"/", "/h ...

  4. 使用MyEclipse开发Java EE应用:企业级应用程序项目(下)

    你开学,我放价!MyEclipse线上狂欢继续!火热开启中>> [MyEclipse最新版下载] 二.项目组织.依赖性和类解析 JEE规范为企业应用程序定义了一个分层的Java类解决策略, ...

  5. Guided Image Filtering

    在图像滤波中,人们最希望的就是可以将图像中的噪声过滤掉的同时,能够让边缘尽可能的保持.噪声属于高频信号,而边缘其实也是一种高频信号,所以一般的滤波器,比如高斯模糊,均值模糊,都是一种低通滤波器,能够将 ...

  6. jenkins系列(9)--插件之Archive The Artifacts

    点击标题下「蓝色微信名」可快速关注 坚持的是分享,搬运的是知识,图的是大家的进步,没有收费的培训,没有虚度的吹水,喜欢就关注.转发(免费帮助更多伙伴)等来交流,想了解的知识请留言,给你带来更多价值,是 ...

  7. A+B for Input-Output Practice (VIII)

    A+B for Input-Output Practice (VIII) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...

  8. HDU 3546

    http://acm.hdu.edu.cn/showproblem.php?pid=3546 题意:10个寄存器初值为1,有加乘赋值运算,最多30w次运算,大数最多5000位,问最后10个寄存器的结果 ...

  9. 按照Right-BICEP要求设计四则运算2程序的单元测试用例

    Right——结果是否正确? B——是否所有的边界条件都是正确的? I——能查一下反响关联吗? C——能用其它手段交叉检查一下吗? E——你是否可以强制错误条件发生? P——是否满足性能要求? 测试计 ...

  10. 了解WCF的前世今生之实现服务端(一)

    http://www.cnblogs.com/jiagoushi/archive/2013/03/15/2962351.html 1.WCF是对现有的分布式通信技术的一个整合,其中包括Com/DCom ...