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. 怎么理解 Bean、Controller、Service、Servicelmpl、Mapper

    主要是对java的各层级介绍.叫法可能不一样,但实现的逻辑都差不多,扔给我的代码中是四个层,分别是Bean层.Controller层.Service层.Servicelmpl层.Mapper层. Be ...

  2. [复习随笔]python_dcgan网络复习小知识:模型定义

    定义参数 dataroot - the path to the root of the dataset folder. We will talk more about the dataset in t ...

  3. vue-test -----ListDemo 列表渲染

    <template> <h3>数组</h3> <button @click="addnums">添加数据</button> ...

  4. Helm Chart 部署 Redis 的完美指南

    目录 一.Helm介绍 二.安装Helm 三.配置Helm的repository 四.部署chart(以部署redis为例) 1. 搜索chart 2. 拉取chart 3. 修改values.yam ...

  5. LCIS最长公共上升子序列!HDU-1423

    This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence ...

  6. 【C++】【图像处理】形态学处理(腐蚀、膨胀)算法解析(以.raw格式的图像为基础进行图像处理、gray levels:256)

    1 void erosion(BYTE* image, int w, int h, BYTE* outImg) 2 { 3 int rept; 4 //腐蚀 5 memcpy(outImg, imag ...

  7. Python——第二章:单引号(')、双引号(")、花括号 {}的用法及注意事项

    在Python中,字符串可以用单引号(')或双引号(")括起来,它们在用法上没有本质区别.你可以根据个人偏好来选择使用单引号或双引号来创建字符串. 例如: 使用单引号括起的字符串: prin ...

  8. [Acwing 164. 可达性统计] 题解报告

    事实上,这道题并不需要拓扑排序.(当然,拓扑排序还是更快) 题目分析 首先,题目中说了,这是一个有向无环图,所以,我们可以考虑 \(\texttt{DP}\) / 记搜 / 拓扑排序 来解决这道题. ...

  9. 基于 Docker 打造前端持续集成开发环境

    基于 Docker 打造前端持续集成开发环境 写在前面: 这不是一篇有新意的文章,因为这篇文章半年前我就发布在其他平台上过,为什么在知乎上旧文新发? 除了想要把发布在其他地方的文章统一放到知乎上之外, ...

  10. vue获取公网ip

    <template> <div> <div>Your Public IP: {{publicIP}}</div> </div> </t ...