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;
namespace notifyIconShow
{
public partial class notifyIconShow : Form
{
public notifyIconShow()
{
InitializeComponent();
}
#region//设置鼠标放在托盘图标上面的文字
/// <summary>
/// 方法名称:notifyIconShow_Load(窗体加载事件)
/// 方法作用:设置鼠标放在托盘图标上面的文字
/// 完成日期:2010年5月16日
/// 作者:心语
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIconShow_Load(object sender, EventArgs e)
{
//设置鼠标放在托盘图标上面的文字
this.notifyIcon1.Text = "心语托盘图标";
}
#endregion
#region//创建对象及声明变量
//创建NotifyIcon对象
NotifyIcon notifyicon = new NotifyIcon();
//创建托盘图标对象
Icon ico = new Icon("Clock2.ico");
//创建托盘菜单对象
ContextMenu notifyContextMenu = new ContextMenu();
#endregion
#region//隐藏任务栏图标,显示托盘图标
/// <summary>
/// 方法名称:notifyIconShow_SizeChanged(窗体大小改变后事件)
/// 方法作用:隐藏任务栏图标,显示托盘图标
/// 完成日期:2010年5月16日
/// 作者:心语
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIconShow_SizeChanged(object sender, EventArgs e)
{
//判断是否选择的是最小化按钮
if (WindowState == FormWindowState.Minimized)
{
//托盘显示图标等于托盘图标对象
//注意notifyIcon1是控件的名字而不是对象的名字
notifyIcon1.Icon = ico;
//隐藏任务栏区图标
this.ShowInTaskbar = false;
//图标显示在托盘区
notifyicon.Visible = true;
}
}
#endregion
#region//还原窗体
/// <summary>
/// 方法名称:notifyIcon1_Click(托盘图标单击)
/// 方法作用:还原窗体
/// 完成日期:2010年5月16日
/// 作者:心语
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIcon1_Click(object sender, EventArgs e)
{
//判断是否已经最小化于托盘
if (WindowState == FormWindowState.Minimized)
{
//还原窗体显示
WindowState = FormWindowState.Normal;
//激活窗体并给予它焦点
this.Activate();
//任务栏区显示图标
this.ShowInTaskbar = true;
//托盘区图标隐藏
notifyicon.Visible = false;
}
}
#endregion
}
}

在托盘显示图标

class Program
{
static void Main(string[] args)
{
int n = m(, );
System.Console.WriteLine("最小公倍数为:" + n.ToString());
System.Console.Read();
}
static int f(int a, int b)//最大公约数
{
if (a < b) { a = a + b; b = a - b; a = a - b; }
return (a % b == ) ? b : f(a % b, b);
}
static int m(int a, int b)//最小公倍数
{
return a * b / f(a, b);
}
}

求最小公倍数

/// <summary>
/// 把汉字转换成拼音(全拼)
/// </summary>
/// <param name="hzString">汉字字符串</param>
/// <returns>转换后的拼音(全拼)字符串</returns>
public static string ConvertE(string hzString)
{
// 匹配中文字符
Regex regex = new Regex("^[\u4e00-\u9fa5]$");
byte[] array = new byte[];
string pyString = "";
int chrAsc = ;
int i1 = ;
int i2 = ;
char[] noWChar = hzString.ToCharArray();
for (int j = ; j < noWChar.Length; j++)
{
// 中文字符
if (regex.IsMatch(noWChar[j].ToString()))
{
array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString());
i1 = (short)(array[]);
i2 = (short)(array[]);
chrAsc = i1 * + i2 - ;
if (chrAsc > && chrAsc < )
{
pyString += noWChar[j];
}
else
{
// 修正部分文字
if (chrAsc == -) // 修正“圳”字
pyString += "Zhen";
else
{
for (int i = (pyValue.Length - ); i >= ; i--)
{
if (pyValue[i] <= chrAsc)
{
pyString += pyName[i];
break;
}
}
}
}
}
// 非中文字符
else
{
pyString += noWChar[j].ToString();
}
}
return pyString;
}
private static int[] pyValue = new int[]
{
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-, -,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-
};
private static string[] pyName = new string[]
{
"A","Ai","An","Ang","Ao","Ba","Bai","Ban","Bang","Bao","Bei","Ben",
"Beng","Bi","Bian","Biao","Bie","Bin","Bing","Bo","Bu","Ba","Cai","Can",
"Cang","Cao","Ce","Ceng","Cha","Chai","Chan","Chang","Chao","Che","Chen","Cheng",
"Chi","Chong","Chou","Chu","Chuai","Chuan","Chuang","Chui","Chun","Chuo","Ci","Cong",
"Cou","Cu","Cuan","Cui","Cun","Cuo","Da","Dai","Dan","Dang","Dao","De",
"Deng","Di","Dian","Diao","Die","Ding","Diu","Dong","Dou","Du","Duan","Dui",
"Dun","Duo","E","En","Er","Fa","Fan","Fang","Fei","Fen","Feng","Fo",
"Fou","Fu","Ga","Gai","Gan","Gang","Gao","Ge","Gei","Gen","Geng","Gong",
"Gou","Gu","Gua","Guai","Guan","Guang","Gui","Gun","Guo","Ha","Hai","Han",
"Hang","Hao","He","Hei","Hen","Heng","Hong","Hou","Hu","Hua","Huai","Huan",
"Huang","Hui","Hun","Huo","Ji","Jia","Jian","Jiang","Jiao","Jie","Jin","Jing",
"Jiong","Jiu","Ju","Juan","Jue","Jun","Ka","Kai","Kan","Kang","Kao","Ke",
"Ken","Keng","Kong","Kou","Ku","Kua","Kuai","Kuan","Kuang","Kui","Kun","Kuo",
"La","Lai","Lan","Lang","Lao","Le","Lei","Leng","Li","Lia","Lian","Liang",
"Liao","Lie","Lin","Ling","Liu","Long","Lou","Lu","Lv","Luan","Lue","Lun",
"Luo","Ma","Mai","Man","Mang","Mao","Me","Mei","Men","Meng","Mi","Mian",
"Miao","Mie","Min","Ming","Miu","Mo","Mou","Mu","Na","Nai","Nan","Nang",
"Nao","Ne","Nei","Nen","Neng","Ni","Nian","Niang","Niao","Nie","Nin","Ning",
"Niu","Nong","Nu","Nv","Nuan","Nue","Nuo","O","Ou","Pa","Pai","Pan",
"Pang","Pao","Pei","Pen","Peng","Pi","Pian","Piao","Pie","Pin","Ping","Po",
"Pu","Qi","Qia","Qian","Qiang","Qiao","Qie","Qin","Qing","Qiong","Qiu","Qu",
"Quan","Que","Qun","Ran","Rang","Rao","Re","Ren","Reng","Ri","Rong","Rou",
"Ru","Ruan","Rui","Run","Ruo","Sa","Sai","San","Sang","Sao","Se","Sen",
"Seng","Sha","Shai","Shan","Shang","Shao","She","Shen","Sheng","Shi","Shou","Shu",
"Shua","Shuai","Shuan","Shuang","Shui","Shun","Shuo","Si","Song","Sou","Su","Suan",
"Sui","Sun","Suo","Ta","Tai","Tan","Tang","Tao","Te","Teng","Ti","Tian",
"Tiao","Tie","Ting","Tong","Tou","Tu","Tuan","Tui","Tun","Tuo","Wa","Wai",
"Wan","Wang","Wei","Wen","Weng","Wo","Wu","Xi","Xia","Xian","Xiang","Xiao",
"Xie","Xin","Xing","Xiong","Xiu","Xu","Xuan","Xue","Xun","Ya","Yan","Yang",
"Yao","Ye","Yi","Yin","Ying","Yo","Yong","You","Yu","Yuan","Yue","Yun",
"Za", "Zai","Zan","Zang","Zao","Ze","Zei","Zen","Zeng","Zha","Zhai","Zhan",
"Zhang","Zhao","Zhe","Zhen","Zheng","Zhi","Zhong","Zhou","Zhu","Zhua","Zhuai","Zhuan",
"Zhuang","Zhui","Zhun","Zhuo","Zi","Zong","Zou","Zu","Zuan","Zui","Zun","Zuo"
};

汉字转拼音

//导入该命名空间
using System.Diagnostice;
Stopwatch watch=new Stopwatch ();
watch.Start();
/*
此处为要计算的运行代码
*/
watch.Stop();
//获取当前实例测量得出的总运行时间(以毫秒为单位)
string time = watch.ElapsedMilliseconds.ToString();

计算代码运行时间

protected void Page_Load(object sender, EventArgs e)
{
int m = System.DateTime.Today.Month;
int y = System.DateTime.Today.Year;
int d = System.DateTime.Today.Day;
int weeks = getWeekDay(y, m, d);
switch (weeks)
{
case :
this.TextBox1.Text = "星期一";
break;
case :
this.TextBox1.Text = "星期二";
break;
case :
this.TextBox1.Text = "星期三";
break;
case :
this.TextBox1.Text = "星期四";
break;
case :
this.TextBox1.Text = "星期五";
break;
case :
this.TextBox1.Text = "星期六";
break;
case :
this.TextBox1.Text = "星期日";
break;
}
}
/// <summary>根据日期,获得星期几</summary>
/// <param name="y">年</param>
/// <param name="m">月</param>
/// <param name="d">日</param>
/// <returns>星期几,1代表星期一;7代表星期日</returns>
public static int getWeekDay(int y, int m, int d)
{
if (m == ) m = ;
if (m == ) m = ;
int week = (d + * m + * (m + ) / + y + y / - y / + y / ) % + ;
return week;
}

根据日期获取星期方法

/// <summary>
/// C# 删除文件夹
/// 用法: DeleteFolder(@"c:\\1");
/// </summary>
/// <param name="dir"></param>
private static void DeleteFolder(string dir)
{
// 循环文件夹里面的内容
foreach (string f in Directory.GetFileSystemEntries(dir))
{
// 如果是文件存在
if (File.Exists(f))
{
FileInfo fi = new FileInfo(f);
if (fi.Attributes.ToString().IndexOf("Readonly") != )
{
fi.Attributes = FileAttributes.Normal;
}
// 直接删除其中的文件
File.Delete(f);
}
else
{
// 如果是文件夹存在
// 递归删除子文件夹
DeleteFolder(f);
}
}
// 删除已空文件夹
Directory.Delete(dir);
}

删除文件夹的方法

OperatingSystem os = System.Environment.OSVersion;
Console.WriteLine(“Platform: {}”, os.Platform);
Console.WriteLine(“Service Pack: {}”, os.ServicePack);
Console.WriteLine(“Version: {}”, os.Version);
Console.WriteLine(“VersionString: {}”, os.VersionString);
Console.WriteLine(“CLR Version: {}”, System.Environment.Version); //在我的Windows 7系统中,输出以下信息
Platform: Win32NT
Service Pack:
Version: 6.1.7600.0
VersionString: Microsoft Windows NT 6.1.7600.0
CLR Version: 4.0.21006.1

读取操作系统和CLR的版本

//可以通过Windows Management Instrumentation (WMI)提供的接口读取所需要的信息。
private static UInt32 CountPhysicalProcessors()
{
ManagementObjectSearcher objects = new ManagementObjectSearcher(
“SELECT * FROM Win32_ComputerSystem”);
ManagementObjectCollection coll = objects.Get();
foreach(ManagementObject obj in coll)
{
return (UInt32)obj[“NumberOfProcessors”];
}
return ;
}
private static UInt64 CountPhysicalMemory()
{
ManagementObjectSearcher objects =new ManagementObjectSearcher(
“SELECT * FROM Win32_PhysicalMemory”);
ManagementObjectCollection coll = objects.Get();
UInt64 total = ;
foreach (ManagementObject obj in coll)
{
total += (UInt64)obj[“Capacity”];
}
return total;
} //请添加对程序集System.Management的引用,确保代码可以正确编译。
Console.WriteLine(“Machine: {}”, Environment.MachineName);
Console.WriteLine(“# of processors (logical): {}”, Environment.ProcessorCount);
Console.WriteLine(“# of processors (physical): {}” CountPhysicalProcessors());
Console.WriteLine(“RAM installed: {:N0} bytes”, CountPhysicalMemory());
Console.WriteLine(“Is OS -bit? {}”, Environment.Is64BitOperatingSystem);
Console.WriteLine(“Is process -bit? {}”, Environment.Is64BitProcess);
Console.WriteLine(“Little-endian: {}”, BitConverter.IsLittleEndian);
foreach (Screen screen in System.Windows.Forms.Screen.AllScreens)
{
Console.WriteLine(“Screen {}”, screen.DeviceName);
Console.WriteLine(“\tPrimary {}”, screen.Primary);
Console.WriteLine(“\tBounds: {}”, screen.Bounds);
Console.WriteLine(“\tWorking Area: {}”,screen.WorkingArea);
Console.WriteLine(“\tBitsPerPixel: {}”,screen.BitsPerPixel);
}

读取CPU数量,内存容量

C# 实用代码段的更多相关文章

  1. Phantomjs实用代码段(持续更新中……)

    一.下载 下载链接二.解压安装包 直接解压即可三.配置环境变量 找到高级系统设置,打开它,出现以下图.点击环境变量. 分别点击编辑按钮 分别新建添加当初的解压路径,到bin文件夹.点击确定. 这样,环 ...

  2. js实用代码段(持续更新)

    1.得到一个数,在一个有序数组中应该排在的位置序号: function orderInArr(num,arr) { if(num > arr[0]){ return 1 + arguments. ...

  3. 实用的JS代码段(表单篇)

    整理了下比较实用的Javascript代码段,完整的代码参考 1 多个window.onload方法 由于onload方法时在页面加载完成后,自动调用的.因此被广泛的使用,但是弊端是只能实用onloa ...

  4. 50个实用的jQuery代码段让你成为更好的Web前端工程师

    本文会给你们展示50个jquery代码片段,这些代码能够给你的javascript项目提供帮助.其中的一些代码段是从jQuery1.4.2才开始支持的做法,另一些则是真正有用的函数或方法,他们能够帮助 ...

  5. 50个必备的实用jQuery代码段+ 可以直接拿来用的15个jQuery代码片段

    50个必备的实用jQuery代码段+ 可以直接拿来用的15个jQuery代码片段 本文会给你们展示50个jquery代码片段,这些代码能够给你的javascript项目提供帮助.其中的一些代码段是从j ...

  6. 50个必备的实用jQuery代码段

    本文会给你们展示50个jquery代码片段,这些代码能够给你的javascript项目提供帮助.其中的一些代码段是从jQuery1.4.2才开始支持的做法,另一些则是真正有用的函数或方法,他们能够帮助 ...

  7. chrome小书签-实用的小功能-javascript代码段

    1.打印页面的所有脚本引用文件及代码段: javascript:var scriptarray=document.getElementsByTagName("script");fo ...

  8. 50个必备的实用jQuery代码段(转载)

    本文会给你们展示50个jquery代码片段,这些代码能够给你的javascript项目提供帮助.其中的一些代码段是从jQuery1.4.2才开始支持的做法,另一些则是真正有用的函数或方法,他们能够帮助 ...

  9. 即学即用的 30 段 Python 实用代码

    [☞ 分享:最全最新的Python学习大礼包 ☜ 点击查看](https://mp.weixin.qq.com/s?__biz=MzU2MzgyODA4OA==&mid=100000592&a ...

随机推荐

  1. MapReduce 简单开发

    先给出 maven 依赖配置 <properties> <hadoop.version>2.6.0</hadoop.version> </properties ...

  2. nginx docker 命令: command not found

    1. ps: command not found 使用如下命令安装 apt-get update && apt-get -y install procps 2. vim: comman ...

  3. 平台级 SAAS 架构的基础:统一身份管理系统

    https://my.oschina.net/bochs/blog/2248954 业内在用户统一身份认证及授权管理领域,主要关注 4 个方面:集中账号管理(Account).集中认证管理(Authe ...

  4. P1908 逆序对-(cdq分治)

    https://www.luogu.org/problem/P1908 沿用归并排序的思想求逆序对. 坑1:结果爆int型,需要用longlong 坑2:相对于归并排序,在比较的时候多了一个等号 举例 ...

  5. Flex弹性盒模型(新老版本完整)--移动端开发整理笔记(二)

    Flex布局 Flex即Flexible Box,写法为:display:flex(旧版:display: -webkit-box) 在Webkit内核下,需要加-webkit前缀: .box{ di ...

  6. 【mybatis】清空数据库表数据

    <update id="truncateTable"> truncate table ${tableName} </update> <update i ...

  7. 使用flow提升js代码的健壮性

    https://www.jianshu.com/p/7716dc8b2206    Flow基本语法及使用 https://www.cnblogs.com/tianxiangbing/p/flow.h ...

  8. ESA2GJK1DH1K升级篇: 远程升级准备工作: 安装Web服务器

    前言 大家可以安装Apache,Tomcat,nginx 等Web服务器软件,这篇文章安装 OpenResty 作为Web服务器软件,该软件安装在云端电脑,如果想 安装到自己本地电脑实现该功能,可使用 ...

  9. 1. Spring Cloud Greenwich SR2 概览

    Spring Cloud provides tools for developers to quickly build some of the common patterns in distribut ...

  10. 踩iviewui中Select 选择器两级联动,重置查询条件时第二级数据无法清除的坑

    小颖公司最近做的项目用的vue+iviewui+axios,在做项目的过程中,遇到一个问题: 二级联动的下拉框,第一个下拉框一直都有值,第二个下拉框是在选择了第一个下拉框之后采取调用ajax获取其值, ...