1.  实现待查询功能的combox

 private void Frm_Main_Load(object sender, EventArgs e)
{
cbox_Find.Items.Clear();//清空ComboBox集合
cbox_Find.Items.Add("C#编程词典");//向ComboBox集合添加元素
cbox_Find.Items.Add("C#编程宝典");//向ComboBox集合添加元素
cbox_Find.Items.Add("C#视频学");//向ComboBox集合添加元素
cbox_Find.Items.Add("C#范例宝典");//向ComboBox集合添加元素
cbox_Find.Items.Add("C#从入门到精通");//向ComboBox集合添加元素
cbox_Find.Items.Add("C#范例大全");//向ComboBox集合添加元素
} private void btn_Begin_Click(object sender, EventArgs e)
{
cbox_Find.AutoCompleteMode = //设置自动完成的模式
AutoCompleteMode.SuggestAppend;
cbox_Find.AutoCompleteSource = //设置自动完成字符串的源
AutoCompleteSource.ListItems;
}

2  在combox下拉列表中显示图片

        private ImageList G_ImageList;//声明ImageList字段

        private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e)
{
if (G_ImageList != null)//判断ImageList是否为空
{
Graphics g = e.Graphics;//得到绘图对象
Rectangle r = e.Bounds;//得到绘图范围
Size imageSize = G_ImageList.ImageSize;//获取图像大小
if (e.Index >= 0)//判断是否有绘制项
{
Font fn = new Font("宋体", 10, FontStyle.Bold);//创建字体对象
string s = cbox_DisplayPictures.Items[e.Index].ToString();//得到绘制项的字符串
DrawItemState dis = e.State;
if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r);//画条目背景
G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串
r.Left + imageSize.Width, r.Top);
e.DrawFocusRectangle();//显示取得焦点时的虚线框
}
else
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r);//画条目背景
G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串
r.Left + imageSize.Width, r.Top);
e.DrawFocusRectangle();//显示取得焦点时的虚线框
}
}
}
} private void btn_Begin_Click(object sender, EventArgs e)
{
btn_Begin.Enabled = false;//停用开始按钮
cbox_DisplayPictures.DrawMode = DrawMode.OwnerDrawFixed;//设置绘制元素方式
cbox_DisplayPictures.DropDownStyle = //设置组合框样式
ComboBoxStyle.DropDownList;
cbox_DisplayPictures.Items.Add("小车");//添加项
cbox_DisplayPictures.Items.Add("卡车");//添加项
cbox_DisplayPictures.Items.Add("工具");//添加项
cbox_DisplayPictures.Items.Add("朋友");//添加项
G_ImageList = new ImageList();//创建ImageList对象
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.a);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.b);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.c);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.d);//添加图片
}

3.实现气泡提示窗口

        private void clewButton_Click(object sender,EventArgs e)
{
this.notifyIcon1.Visible = true;//设置提示控件可见
this.notifyIcon1.ShowBalloonTip(1000,"当前时间:",DateTime.Now.ToLocalTime().ToString(),ToolTipIcon.Info);//显示气泡提示
} private void closeButton_Click(object sender,EventArgs e)
{
this.notifyIcon1.Visible = false;//设置提示控件不可见
} private void notifyIcon1_MouseMove(object sender,MouseEventArgs e)
{
this.notifyIcon1.ShowBalloonTip(1000, "当前时间:", DateTime.Now.ToLocalTime().ToString(), ToolTipIcon.Info);//显示气泡提示
}

4.在状态栏实时显示系统运行时间

        private DateTime G_DateTime;//声明时间字段

        private void Frm_Main_Load(object sender, EventArgs e)
{
G_DateTime = DateTime.Now;//得到系统当前时间
Thread P_th = new Thread(//创建线程
() =>//使用Lambda表达式
{
while (true)//无限循环
{
TimeSpan P_TimeSpan =//得到时间差
DateTime.Now - G_DateTime;
Invoke(//调用窗体线程
(MethodInvoker)(() =>//使用Lambda表达式
{
tssLabel_Time.Text =//显示程序启动时间
string.Format(
"系统已经运行: {0}天{1}小时{2}分{3}秒",
P_TimeSpan.Days, P_TimeSpan.Hours,
P_TimeSpan.Minutes, P_TimeSpan.Seconds);
}));
Thread.Sleep(1000);//线程挂起1秒钟
}
});
P_th.IsBackground = true;//设置为后台线程
P_th.Start();//开始执行线程
}

5. 打开指定word文档

        private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "*.doc|*.doc|*.docx|*.docx";//筛选文件
openFileDialog1.InitialDirectory = @"I:\软谋12后端\20190424Advanced12Course47SOA-WebServcie\20190424Advanced12Course47SOA-WebServcie\"; if (openFileDialog1.ShowDialog() == DialogResult.OK)//弹出打开文件对话框
{
string fileName = openFileDialog1.FileName; Process.Start(fileName);
}
}

6. 利用图片对文本进行加密解密

        //打开图片
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "jpg,bmp,gif|*.jpg;*.gif;*.bmp";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.ImageLocation = openFileDialog1.FileName;
}
}
//打开加密文件
private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "文本文件|*.txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
// 加密
private void button3_Click(object sender, EventArgs e)
{
try
{
if (pictureBox1.ImageLocation == null)
{ MessageBox.Show("请选择一幅图片用于加密"); return; }
if (textBox1.Text == "")
{ MessageBox.Show("请选择加密文件路径"); return; }
//图片流
FileStream fsPic = new FileStream(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);
//加密文件流
FileStream fsText = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
//初始化Key IV
byte[] bykey = new byte[16];
byte[] byIv = new byte[8];
fsPic.Read(bykey, 0, 16);
fsPic.Read(byIv, 0, 8);
//临时加密文件
string strPath = textBox1.Text;//加密文件的路径
int intLent = strPath.LastIndexOf("\\") + 1;
int intLong = strPath.Length;
string strName = strPath.Substring(intLent, intLong - intLent);//要加密的文件名称
string strLinPath = "C:\\" + strName;//临时加密文件路径,所以被加密的文件不可以放在C盘的根目录下
FileStream fsOut = File.Open(strLinPath, FileMode.Create, FileAccess.Write);
//开始加密
RC2CryptoServiceProvider desc = new RC2CryptoServiceProvider();//des进行加
BinaryReader br = new BinaryReader(fsText);//从要加密的文件中读出文件内容
CryptoStream cs = new CryptoStream(fsOut, desc.CreateEncryptor(bykey, byIv), CryptoStreamMode.Write);//写入临时加密文件
cs.Write(br.ReadBytes((int)fsText.Length), 0, (int)fsText.Length);//写入加密流
cs.FlushFinalBlock();
cs.Flush();
cs.Close();
fsPic.Close();
fsText.Close();
fsOut.Close();
File.Delete(textBox1.Text.TrimEnd());//册除原文件
File.Copy(strLinPath, textBox1.Text);//复制加密文件
File.Delete(strLinPath);//册除临时文件
MessageBox.Show("加密成功");
pictureBox1.ImageLocation = null;
textBox1.Text = "";
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
} } //解密
private void button4_Click(object sender, EventArgs e)
{
try
{
//图片流
FileStream fsPic = new FileStream(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);
//解密文件流
FileStream fsOut = File.Open(textBox1.Text, FileMode.Open, FileAccess.Read);
//初始化Key IV
byte[] bykey = new byte[16];
byte[] byIv = new byte[8];
fsPic.Read(bykey, 0, 16);
fsPic.Read(byIv, 0, 8);
//临时解密文件
string strPath = textBox1.Text;//加密文件的路径
int intLent = strPath.LastIndexOf("\\") + 1;
int intLong = strPath.Length;
string strName = strPath.Substring(intLent, intLong - intLent);//要加密的文件名称
string strLinPath = "C:\\" + strName;//临时解密文件路径
FileStream fs = new FileStream(strLinPath, FileMode.Create, FileAccess.Write);
//开始解密
RC2CryptoServiceProvider desc = new RC2CryptoServiceProvider();//des进行解
CryptoStream csDecrypt = new CryptoStream(fsOut, desc.CreateDecryptor(bykey, byIv), CryptoStreamMode.Read);//读出加密文件
BinaryReader sr = new BinaryReader(csDecrypt);//从要加密流中读出文件内容
BinaryWriter sw = new BinaryWriter(fs);//写入解密流
sw.Write(sr.ReadBytes(Convert.ToInt32(fsOut.Length)));//
sw.Flush();
sw.Close();
sr.Close();
fs.Close();
fsOut.Close();
fsPic.Close();
csDecrypt.Flush(); File.Delete(textBox1.Text.TrimEnd());//册除原文件
File.Copy(strLinPath, textBox1.Text);//复制加密文件
File.Delete(strLinPath);//册除临时文件
MessageBox.Show("解密成功");
pictureBox1.ImageLocation = null;
textBox1.Text = "";
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}

winform 各种小功能的更多相关文章

  1. C#、Java中的一些小功能点总结(持续更新......)

    前言:在项目中,有时候一些小的功能点,总是容易让人忽略,但是这些功能加在项目中往往十分的有用,因此笔者在这里总结项目中遇到的一些实用的小功能点,以备用,并持续更新...... 1.禁用DataGrid ...

  2. C#之winform 猜拳小游戏

    C#之winform 猜拳小游戏 1.建立项目文件 2.进行界面布局 2.1 玩家显示(控件:label) 2.2  显示玩家进行选择的控件(控件:label) 2.3 电脑显示(控件:label) ...

  3. js小功能整理

    /** * 判断是否包含字符串某字符串 * @param {[type]} str [被检测的字符串] * @param {[type]} substr [检测是否含有的字符串] * @return ...

  4. iOS--知识综合应用成就时髦小功能点

    iOS--知识综合应用成就时髦小功能点

  5. Java实现点击一个Jlabel增加一个Jlabel的小功能

    当界面生成以后,自己想做一个点击一个Jlabel增加一个Jlabel,即类似于QQ的添加好友以后可以及时的加进一个好友.自己做了好久,发现不能及时刷新.在网上查了一下,然后自己研究了一小会.发现需要v ...

  6. Servlet的5种方式实现表单提交(注册小功能),后台获取表单数据

    用servlet实现一个注册的小功能 ,后台获取数据. 注册页面: 注册页面代码 : <!DOCTYPE html> <html> <head> <meta ...

  7. android 常用小功能(第二版)

    经历过一段岁月,转眼2013的半年都过去了,第二版整理好的小功能,答应大家发布的,直到今日,终于和大家相见了,第二版没有第一版多,大家也可以去参考第一版的内容,希望大家使用愉快! 目录: 1.获取当前 ...

  8. NSFileManager文件操作的十个小功能

    NSFileManager文件操作的十个小功能 NSFileManager是一个单列类,也是一个文件管理器.可以通过NSFileManager创建文件夹.创建文件.写文件.读文件内容等等基本功能. 下 ...

  9. javascript实现的一个信息提示的小功能/

    //什么状况.CSDN的排版怎么这么多状况,还是本人太次?调整几次都没弄好.最后一遍了-- 最近由于公司业务问题.须要做一些面向公众的平台,于是对UI要求会高一点, 对于传统的alert的这样的方式来 ...

  10. Visual Studio Debugger中七个鲜为人知的小功能

    Visual Studio debugger是一个很棒的调试工具,可以帮助程序猿们快速地发现和解决问题.这里给大家简单介绍一下VS调试工具中的七个鲜为人知的小功能. 1.    一键跳转到指定语句 调 ...

随机推荐

  1. 华为防火墙1day?

    背景信息 缺省情况下,FW通过8887端口提供内置的本地Portal认证页面,用户可以主动访问或HTTP重定向至认证页面(https://接口IP地址:8887)进行本地Portal认证. 当企业部署 ...

  2. 华企盾DSC申请解密在键盘中勾选会自动取消

    解决方法:打开系统偏好设置-键盘--服务,由于服务中超出了系统支持的最大菜单数,删除两个即可

  3. @Conditional+@Configuration有没有搞头?

    日拱一卒,功不唐捐. 在了解 @Conditional 之前先花 10 秒钟复习一下 @Configuration 这个注解. @Configuration 是干什么? 是配合 @Bean 注解来配置 ...

  4. ElasticSearch的简单api介绍

    1:ElasticSearch是什么? Elasticsearch 是一个分布式的免费开源搜索和分析引擎 适用于包括文本.数字.地理空间.结构化和非结构化数据等在内的所有类型的数据 Elasticse ...

  5. 2023-06-30:给你一个 rows * cols 大小的矩形披萨和一个整数 k, 矩形包含两种字符: ‘A‘ (表示苹果)和 ‘.‘ (表示空白格子), 你需要切披萨 k-1 次,得到 k 块披

    2023-06-30:给你一个 rows * cols 大小的矩形披萨和一个整数 k, 矩形包含两种字符: 'A' (表示苹果)和 '.' (表示空白格子), 你需要切披萨 k-1 次,得到 k 块披 ...

  6. 快速入门Mybatis完成基本CURD(注解实现)

    一.什么是Mybatis? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射. MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. MyB ...

  7. Windows使用docker踩坑记录

    一.安装踩坑 安装时会让你选择:是否使用Windows容器 Use Windows containers instead of Linux containers(this can be changed ...

  8. 痞子衡嵌入式:原来i.MXRT1170内部RAM的ECC初始化工作可全部由ROM完成

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是i.MXRT1170内部RAM的ECC初始化工作可全部由ROM完成. 痞子衡之前写了三篇文章 <M7 FlexRAM ECC> ...

  9. 华为云Classroom聚焦人才数字化转型,引领智慧教育改革新模式

    随着教育行业数字化转型进程加快,利用现代化云端技术手段,线上线下相结合方式建立的全新OMO产教融合一体化已成为行业趋势.华为云Classroom平台沉淀了华为多年研发实践经验和多种前沿技术,以赋能伙伴 ...

  10. ROMA集成关键技术:增量数据集成

    摘要:本文将详解ROMA集成关键技术-增量数据集成技术. 本文分享自华为云社区<ROMA集成关键技术(2)-增量数据集成技术>,作者:华为云PaaS服务小智 . 1.概述 ROMA平台的核 ...