自绘图片下拉项 combobox listbox
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的更多相关文章
- C#中如何将combox中的下拉项和一个枚举中的各项进行绑定
实现一个combobox,将其各个下拉项与枚举进行绑定 效果图如下: 代码详解如下: 枚举: public enum StoreSite { /// <summary> /// 未知 // ...
- 刷新各ifream当前页,下拉项改变触发事件js,给选中项加背景色js
<script type="text/javascript" language="javascript"> //刷新框架各页面 function r ...
- python: HTML之 鼠标放上去下拉项字体显示不同颜色
鼠标放上去下拉项字体显示不同颜色 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "h ...
- 使用AJAX填充<select>标签下拉项,没有显示指定的option项
newCarInfo.js代码如下: $(function() { // 获取燃油种类 url = "basicFuelType_queryAll.action"; ...
- Dynamics CRM2013 picklist下拉项行数控制
CRM2013和前面几个版本相比有了很大的变化,本文中讲述的picklist亦然.CRM2013的picklist效果图如下所示 目前能看到的是会根据下拉内容项的数量不同而显示不同的下拉行数,但有时客 ...
- jqgrid 配置分页大小及下拉项
如何配置分页大小的下拉项?显示效果如下: 通过 rowNum 来设置默认分页大小 通过 rowList 来设置分页下拉. rowList 的值为一个数组,比如:[10,20,30] $(" ...
- Qt下拉对话框 ComboBox的用法
介绍 ComboBox是Qt的下拉菜单的一个控件,通过下拉菜单选择不同的选项,样式如图: 基本用法 m_ComBox = ui.comboBox; //设置默认显示值的索引,从0开始 m_ComBox ...
- 下拉框combobox用法&级联餐单
如果下来内容不用后台取数据,直接写死的话不用url属性,直接用data即可: <input id="orderstate" name="orderstate&quo ...
- multiselect获取选中的多个下拉项的值(逗号分割的字符串)
/*传入下拉select标签*/ function get_selected(mslt_employees) { var emplo =mslt_employees.multiselect(" ...
随机推荐
- 太完美 TWM000极度精简版XP20130123终结美化版
TWM000极度精简版XP20130123终结美化版:蛋蛋20130123终结版为蓝本,虫子提供的美化包进行了美化.此版经测试完美在Z77主板开启AHCI安装,此为最终版之美化版!LiteXPMH.i ...
- STL标准库-容器适配器
技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 上一节介绍了仿函数适配器,这节主要介绍容器适配器和迭代器适配器的概念,其实容器适配器和迭代器其适配器就是封装了一些其他class ...
- mysql 试图
关系型数据库中的数据是由一张一张的二维关系表所组成,简单的单表查询只需要遍历一个表,而复杂的多表查询需要将多个表连接起来进行查询任务.对于复杂的查询事件,每次查询都需要编写MySQL代码效率低下.为了 ...
- Linux C 文件操作函数(~上善止水~)
翻翻笔记,整理一下 C 语言中的文件操作函数 ~~~~~~,多注意细节,maybe 细节决定成败~ 1. fopen /* fopen(打开文件) * * 相关函数 open,fclose * * 表 ...
- ReactNative——UI1.登录界面样式设置
使用React 基本组件结合flex 属性,实现简单登录布局UI 效果 效果预览:
- David Silver 强化学习原理 (中文版 链接)
教程的在线视频链接: http://www.bilibili.com/video/av9831889/ 全部视频链接: https://space.bilibili.com/74997410/vide ...
- Windows 7 SP1 多国语言包(MUI language packs)官方下载
为了装一款 Gal Game (为毛不是装 H-Game?),使用 APP 还是太辛苦了,反正相信童鞋们也都用上“瘟妻”了嘛,装个日文的语言包基本上就可以解决问题了.大家都知道只有旗舰版(Wind ...
- 20155338 2016-2017-2 《Java程序设计》第8周学习总结
20155338 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 一.日志 API简介 java++.util.logging包提供了日志功能相关类与接口,不 ...
- js获取 gps坐标
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(pos) { model.address. ...
- Oracle 服务命名(别名)的配置及原理,plsql连接用
Oracle 服务命名(别名)的配置及原理 连接数据库必须配置服务命名(别名,用于plsql的连接),不管是本地还是远程,服务命名即简单命名,简单命名映射到连接描述符,他包含服务的网络位置和标识,配置 ...