C#的icon怎么批量设置? 写了十几个窗体。怎么批量设置用一个icon? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个是批量命名文件的,你可以照这个例子改一下using System;using System.Drawing;using System.Globalization;using System.IO;using System.Linq;using System.Runtime.InteropServices;using System.Windows.Forms;namespace WinFormReName{ public partial class FormFile : Form { #region AnimateWindow [DllImport("user32.dll", EntryPoint = "AnimateWindow")] private static extern bool AnimateWindow(IntPtr handle, int ms, int flags); #endregion private ImageList imageListFile; private ChineseLunisolarCalendar lunarCalendar; public FormFile() { #region InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; lunarCalendar = new ChineseLunisolarCalendar(); imageListFile = new ImageList(); imageListFile.ColorDepth = ColorDepth.Depth32Bit; imageListFile.ImageSize = new Size(32, 32); imageListFile.TransparentColor = Color.Transparent; listViewFile.AllowDrop = true; listViewFile.MultiSelect = false; listViewFile.ShowGroups = true; listViewFile.ShowItemToolTips = true; listViewFile.LargeImageList = imageListFile; listViewFile.SmallImageList = imageListFile; listViewFile.StateImageList = imageListFile; listViewFile.HeaderStyle = ColumnHeaderStyle.None; // 隐藏列标题。 listViewFile.DragEnter += new DragEventHandler(listViewFile_DragEnter); toolComboBoxExt.DropDownStyle = ComboBoxStyle.DropDownList; toolComboBoxView.DropDownStyle = ComboBoxStyle.DropDownList; toolComboBoxView.ComboBox.DataSource = Enum.GetValues(typeof(View)); #endregion } #region FormLoad protected override void OnLoad(EventArgs e) { base.OnLoad(e); AnimateWindow(this.Handle, 1000, 0x20010); // 居中逐渐显示。 } #endregion #region FormClosing protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); AnimateWindow(this.Handle, 1000, 0x10010); // 居中逐渐隐藏。 } #endregion #region DateTimeFormatInfo private void timerInfo_Tick(object sender, EventArgs e) { Application.CurrentCulture.ClearCachedData(); DateTime solar = DateTime.Now; int month = lunarCalendar.GetMonth(solar); int leapMonth = lunarCalendar.GetLeapMonth(lunarCalendar.GetYear(solar)); if (0 < leapMonth && leapMonth <= month) --month; statusLabelTime.Text = string.Format("{0:F} [{1} {2:00}]", solar, DateTimeFormatInfo.CurrentInfo.MonthNames[month - 1], lunarCalendar.GetDayOfMonth(solar)); } #endregion #region LoadItems private void listViewFile_DragEnter(object sender, DragEventArgs e) { DataObject data = e.Data as DataObject; if (data.ContainsFileDropList()) { DirectoryInfo dir = new DirectoryInfo(data.GetFileDropList()[0]); if ((dir.Attributes & FileAttributes.Directory) != 0) LoadFiles(dir); } } private void LoadFiles(DirectoryInfo dir) { toolComboBoxExt.Items.Clear(); imageListFile.Images.Clear(); listViewFile.Groups.Clear(); listViewFile.Items.Clear(); listViewFile.BeginUpdate(); Environment.CurrentDirectory = this.Text = dir.FullName; // 设置当前工作目录。 var query = from info in dir.GetFiles() let Extension = info.Extension.ToLowerInvariant() let Hidden = info.Attributes & FileAttributes.Hidden where Hidden == 0 group info by Extension into Groups orderby Groups.Key ascending select Groups; // 根据文件扩展名分组排序。 foreach (var files in query) { toolComboBoxExt.Items.Add(files.Key); imageListFile.Images.Add(files.Key, Icon.ExtractAssociatedIcon(files.First().Name)); ListViewGroup group = listViewFile.Groups.Add(files.Key, files.Key); foreach (FileInfo info in files) { ListViewItem item = listViewFile.Items.Add(info.Name, files.Key); item.ToolTipText = string.Format("名称: {0}\n大小: {1:#,##0.00} KB\n修改日期: {2:yyyy-MM-dd HH:mm}", info.Name, info.Length / 1024M, info.LastWriteTime); item.Group = group; } } listViewFile.EndUpdate(); } private void toolButtonOpen_Click(object sender, EventArgs e) { if (folderBrowser.ShowDialog(this) == DialogResult.OK) LoadFiles(new DirectoryInfo(folderBrowser.SelectedPath)); } #endregion #region View private void toolComboBoxView_SelectedIndexChanged(object sender, EventArgs e) { listViewFile.View = (View)toolComboBoxView.SelectedItem; } #endregion #region ReNaneFile private void toolTextBoxName_KeyPress(object sender, KeyPressEventArgs e) { foreach (char key in @"\/:*?""<>|") { if (e.Handled = (e.KeyChar == key)) break; } } private void toolButtonName_Click(object sender, EventArgs e) { if (toolComboBoxExt.SelectedIndex < 0) return; foreach (ListViewItem item in listViewFile.Items) { string newName = string.Format("{0}[{1}]{2}", toolTextBoxName.Text, item.Index + 1, toolComboBoxExt.Text); if (File.Exists(newName)) continue; FileInfo info = new FileInfo(item.Text); if (info.Exists) { info.MoveTo(newName); item.Text = info.Name; item.ToolTipText = string.Format("名称: {0}\n大小: {1:#,##0.00} KB\n修改日期: {2:yyyy-MM-dd HH:mm}", info.Name, info.Length / 1024M, info.LastWriteTime); } else item.Remove(); } } private void toolComboBoxExt_SelectedIndexChanged(object sender, EventArgs e) { listViewFile.Items.Clear(); listViewFile.BeginUpdate(); DirectoryInfo dir = new DirectoryInfo(Environment.CurrentDirectory); foreach (FileInfo info in dir.GetFiles("*" + toolComboBoxExt.Text)) { ListViewItem item = listViewFile.Items.Add(info.Name, toolComboBoxExt.Text); item.ToolTipText = string.Format("名称: {0}\n大小: {1:#,##0.00} KB\n修改日期: {2:yyyy-MM-dd HH:mm}", info.Name, info.Length / 1024M, info.LastWriteTime); item.Group = listViewFile.Groups[toolComboBoxExt.Text]; } listViewFile.EndUpdate(); } #endregion }} 谁能告诉我下面图片处理的疑问?谢谢 C#操作文本文件 查找 位置 【C#指针,内存,结构体】结构体byte数组的问题!! 请教大家,一个关于 高并发性,高传输可靠性,高执行效率 的解决方案. c#学了好久 可是现在要做项目了一点头绪都没有 请教各位高手!! 大数据抽奖设计问题 COM 与.net framework 在程序通讯上的区别? C#中如何获得图像的色值?(一道简单的问题,大家快来看看。。。...) 多线程中注册的事件仅执行一次? To acptvc:能不能在windows ce上调用webservice? C#为何要引入属性? Strust2中迭代和if结合取值判断 急急@急!
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;namespace WinFormReName
{
public partial class FormFile : Form
{
#region AnimateWindow
[DllImport("user32.dll", EntryPoint = "AnimateWindow")]
private static extern bool AnimateWindow(IntPtr handle, int ms, int flags);
#endregion private ImageList imageListFile;
private ChineseLunisolarCalendar lunarCalendar; public FormFile()
{
#region
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
lunarCalendar = new ChineseLunisolarCalendar();
imageListFile = new ImageList();
imageListFile.ColorDepth = ColorDepth.Depth32Bit;
imageListFile.ImageSize = new Size(32, 32);
imageListFile.TransparentColor = Color.Transparent;
listViewFile.AllowDrop = true;
listViewFile.MultiSelect = false;
listViewFile.ShowGroups = true;
listViewFile.ShowItemToolTips = true;
listViewFile.LargeImageList = imageListFile;
listViewFile.SmallImageList = imageListFile;
listViewFile.StateImageList = imageListFile;
listViewFile.HeaderStyle = ColumnHeaderStyle.None; // 隐藏列标题。
listViewFile.DragEnter += new DragEventHandler(listViewFile_DragEnter);
toolComboBoxExt.DropDownStyle = ComboBoxStyle.DropDownList;
toolComboBoxView.DropDownStyle = ComboBoxStyle.DropDownList;
toolComboBoxView.ComboBox.DataSource = Enum.GetValues(typeof(View));
#endregion
} #region FormLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AnimateWindow(this.Handle, 1000, 0x20010); // 居中逐渐显示。
}
#endregion #region FormClosing
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
AnimateWindow(this.Handle, 1000, 0x10010); // 居中逐渐隐藏。
}
#endregion #region DateTimeFormatInfo
private void timerInfo_Tick(object sender, EventArgs e)
{
Application.CurrentCulture.ClearCachedData();
DateTime solar = DateTime.Now;
int month = lunarCalendar.GetMonth(solar);
int leapMonth = lunarCalendar.GetLeapMonth(lunarCalendar.GetYear(solar));
if (0 < leapMonth && leapMonth <= month)
--month;
statusLabelTime.Text = string.Format("{0:F} [{1} {2:00}]", solar, DateTimeFormatInfo.CurrentInfo.MonthNames[month - 1], lunarCalendar.GetDayOfMonth(solar));
}
#endregion #region LoadItems
private void listViewFile_DragEnter(object sender, DragEventArgs e)
{
DataObject data = e.Data as DataObject;
if (data.ContainsFileDropList())
{
DirectoryInfo dir = new DirectoryInfo(data.GetFileDropList()[0]);
if ((dir.Attributes & FileAttributes.Directory) != 0)
LoadFiles(dir);
}
} private void LoadFiles(DirectoryInfo dir)
{
toolComboBoxExt.Items.Clear();
imageListFile.Images.Clear();
listViewFile.Groups.Clear();
listViewFile.Items.Clear();
listViewFile.BeginUpdate();
Environment.CurrentDirectory = this.Text = dir.FullName; // 设置当前工作目录。
var query = from info in dir.GetFiles()
let Extension = info.Extension.ToLowerInvariant()
let Hidden = info.Attributes & FileAttributes.Hidden
where Hidden == 0
group info by Extension into Groups
orderby Groups.Key ascending
select Groups; // 根据文件扩展名分组排序。
foreach (var files in query)
{
toolComboBoxExt.Items.Add(files.Key);
imageListFile.Images.Add(files.Key, Icon.ExtractAssociatedIcon(files.First().Name));
ListViewGroup group = listViewFile.Groups.Add(files.Key, files.Key);
foreach (FileInfo info in files)
{
ListViewItem item = listViewFile.Items.Add(info.Name, files.Key);
item.ToolTipText = string.Format("名称: {0}\n大小: {1:#,##0.00} KB\n修改日期: {2:yyyy-MM-dd HH:mm}", info.Name, info.Length / 1024M, info.LastWriteTime);
item.Group = group;
}
}
listViewFile.EndUpdate();
} private void toolButtonOpen_Click(object sender, EventArgs e)
{
if (folderBrowser.ShowDialog(this) == DialogResult.OK)
LoadFiles(new DirectoryInfo(folderBrowser.SelectedPath));
}
#endregion #region View
private void toolComboBoxView_SelectedIndexChanged(object sender, EventArgs e)
{
listViewFile.View = (View)toolComboBoxView.SelectedItem;
}
#endregion #region ReNaneFile
private void toolTextBoxName_KeyPress(object sender, KeyPressEventArgs e)
{
foreach (char key in @"\/:*?""<>|")
{
if (e.Handled = (e.KeyChar == key))
break;
}
} private void toolButtonName_Click(object sender, EventArgs e)
{
if (toolComboBoxExt.SelectedIndex < 0)
return;
foreach (ListViewItem item in listViewFile.Items)
{
string newName = string.Format("{0}[{1}]{2}", toolTextBoxName.Text, item.Index + 1, toolComboBoxExt.Text);
if (File.Exists(newName))
continue;
FileInfo info = new FileInfo(item.Text);
if (info.Exists)
{
info.MoveTo(newName);
item.Text = info.Name;
item.ToolTipText = string.Format("名称: {0}\n大小: {1:#,##0.00} KB\n修改日期: {2:yyyy-MM-dd HH:mm}", info.Name, info.Length / 1024M, info.LastWriteTime);
}
else
item.Remove();
}
} private void toolComboBoxExt_SelectedIndexChanged(object sender, EventArgs e)
{
listViewFile.Items.Clear();
listViewFile.BeginUpdate();
DirectoryInfo dir = new DirectoryInfo(Environment.CurrentDirectory);
foreach (FileInfo info in dir.GetFiles("*" + toolComboBoxExt.Text))
{
ListViewItem item = listViewFile.Items.Add(info.Name, toolComboBoxExt.Text);
item.ToolTipText = string.Format("名称: {0}\n大小: {1:#,##0.00} KB\n修改日期: {2:yyyy-MM-dd HH:mm}", info.Name, info.Length / 1024M, info.LastWriteTime);
item.Group = listViewFile.Groups[toolComboBoxExt.Text];
}
listViewFile.EndUpdate();
}
#endregion
}
}