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. Double H5.0

    Alpha阶段 - 博客链接合集 项目Github地址 Github 敏捷冲刺日志 Alpha冲刺! Day1 - 磨刀 Alpha冲刺! Day2 - 砍柴 Alpha冲刺! Day3 - 砍柴 A ...

  2. spring 定时任务参数配置详解

    注:本文摘自<Quartz Cron 触发器 Cron Expression 的格式>http://blog.csdn.net/yefengmeander/article/details/ ...

  3. css3 制作平滑过度动画

    -webkit-transition(属性渐变) -webkit-transition:CSS属性(none|all|属性)  持续时间  时间函数  延迟时间 CSS属性(transition-pr ...

  4. Android manifest 获取源代码

    /********************************************************************************* * Android manifes ...

  5. python type metaclass

    在python中一切皆对象, 所有类的鼻祖都是type, 也就是所有类都是通过type来创建. 传统创建类 class Foo(object): def __init__(self,name): se ...

  6. leetcode:Symmetric Tree【Python版】

    #error caused by:#1:{} 没有考虑None输入#2:{1,2,2} 没有控制h和t#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变 ...

  7. Mysql ON子句和USING子句

    Mysql ON子句和USING子句   Mysql 中联接SQL语句中,ON子句的语法格式为:table1.column_name = table2.column_name. 当模式设计对联接表的列 ...

  8. 投行的码工 Dead-end job

    发信人: icestonesy (无忧), 信区: Quant 标  题: 投行的码工怎么样? 发信站: BBS 未名空间站 (Sat May 16 23:25:00 2015, 美东) 最近看到不少 ...

  9. JUC集合之 ConcurrentLinkedQueue

    ConcurrentLinkedQueue介绍 ConcurrentLinkedQueue是线程安全的队列,它适用于"高并发"的场景. 它是一个基于链接节点的无界线程安全队列,按照 ...

  10. 从工程文化和运维理念理解Netflix

    http://www.infoq.com/cn/news/2018/01/netflix-engineering-culture 在技术圈儿,Netflix 是一家非常有特色的互联网公司.他们信奉“自 ...